How to define your own database ID - Firebase Xamarin - c#

I have the following database:
And I want to use the "Nome" value as an ID instead of a generated code. Instead of -MzKveR8JIXgWsrph_or I wanted it to be Teste1.
My current insert code looks like this:
MyDatabaseRecord databaserecord = new MyDatabaseRecord
{
Nome = EntryNome.Text.ToString(),
Prato1 = EntryPrt1.Text.ToString(),
Prato2 = EntryPrt2.Text.ToString(),
Sopa = EntrySopa.Text.ToString(),
Contacto = EntryContacto.Text.ToString()
};
firebaseClient.Child("Restaurantes").PostAsync(databaserecord);
What do I need to change in order to set the decided value as a Firebase ID? I've been trying to get there but couldn't yet find the right answer.

The Firebase Realtime Database API for C# follow a REST-ful pattern for its method names. This means that calling POST on a URL creates a resource under that location with an identifier determined by the system. If you want to determine your own identifier, call PUT on the entire path (including that identifier).
So:
firebaseClient.Child("Restaurantes/RestaurantOne").PutAsync(databaserecord);

Related

Get Azure DevOps comment details including comment id in .NET C#

I am trying to get list of comments of a specific Azure DevOps workitem through C# Azure DevOps SDK.
Nuget packages I have used:
Microsoft.TeamFoundationServer.Client 16.170.0
Microsoft.VisualStudio.Services.Client 16.170.0
Here is the C# code to get WorkItem comments:
// create instance of work item tracking http client
var credentials = new VssBasicCredential(string.Empty, PAT);
using (var httpClient = new WorkItemTrackingHttpClient(new Uri(COLLECTION_URI), credentials))
{
// get all comments for this work item
var comments = await httpClient.GetCommentsAsync(workItemId);
}
The "httpClient.GetCommentsAsync" method works fine and returns object of "WorkItemComments" class. The "WorkItemComments" object contains a property named "Comments" of data type "IEnumerable of WorkItemComment". If I further go inside "WorkItemComment" class then I can see only four properties inside it.
Revision
Text
RevisedBy
RevisedDate
So, in short, I am not able to get other details of comment like comment id, created by, created date, modifed by, modified date, etc.
How can I get other details of comments ? Do I need to call any other method ?

How to get the request object for uri in ASP.NET Web API?

I have a requirement within team where I need to create an api, which should provide the user with all available api and corresponding request for which the user requested. I was planning to save the api end point in the DB table and based on the user request, read and get this uri. But I'm not sure how to access the request object assocaited with an api end point from a different api controller.
switch (service.ToUpper())
{
case "MYFUNCTIONALITY":
detail.endPoint = "api/myfunctionality/random";
detail.requestObject = new AutoCreditCardTransactionRequest() { Quantity = 5, AcctmyIDs = myaccts };
break;
default: break;
}
return detail;
In the above code, I have hardcoded the end point and based on the case statement, the request class is also mentioned. As I need to do this for all the end point, I wanted these end point to be moved to DB and then read from that, but issue for me is how to get the request class for the end point rather than specifying the request class
You can use ApiExplorer class's ApiDescriptions property to get ApiDescription for API endpoints then use ApiDescription.ParameterDescriptions property to access the input parameters for the API.. Something like following
ApiParameterDescription paramDesc; // Use appropriate code to populate this
var type = paramDesc.ParameterDescriptor.ParameterType;
var defaultValue = paramDesc.ParameterDescriptor.DefaultValue;

Unexpected Behaviour while trying to update database in consecutive requests - EF 6

I have been dealing with this for days
Summary
I am creating a Social site that will be the back bone for another web application. The hangup is when I submit a request to create a group all goes well, but if I attempt to submit this form again with different data I get a DbEntityValidationException. The exception is related to the ApplicationUser entry.
Details
When I start the Application in Debug mode and submit the Group creation form for the first time it will succeed, adding all the entities into the database as excepted. I have verified this and all looks good. While in the same Debug session, I change the information in the form, to create another group, and submit the form, which leads to the DbEntityValidationException.
The error is related the when I try to insert a SocialGroupMemberModel which contains a reference to the User, and other details related to the users status in the group. The User entry is being marked as added and EntityFramework is trying to insert the User instead of updating. I have attempted to set the Navigation (User) and set the ForeignKey (UserId), both lead to the same error.
I am using HttpContext.Current.GetOwinContext().Get<ApplicationDbContext>();
In the Controller I use ApplicationUserManager to get the User Entity, I then pass this to the Repository to create the group (in either case, either passing the ID, or Entity itself, doesn't work the second time)
Group Creation Code:
var groupInfo = new SocialGroupInfo
{
Created = DateTime.Now,
Description = model.Description,
ShortDescription = model.ShortDescription,
Name = model.Name,
Tags = TagRepo.GetTags(),
Members = new List<SocialGroupMember>()// { member }
};
var groupModel = new SocialGroupModel
{
Slug = model.Slug,
Info = groupInfo
};
Context.SocialGroups.Add(groupModel);
var member = new SocialGroupOwnerModel
{
Joined = DateTime.Now,
UserId = creator
//User = null
//Group = groupInfo
};
groupInfo.Members.Add(member);
//creator.SocialGroups.Add(member);
SaveChanges();
The Validation Error is: "User name ** is already taken" so this leads me to believe that on the second attempt to add the new group, it is attempting to add a new user.
Please ask for any additional information needed, thanks.
This issue was caused by the IoC holding a reference to the previous DbContext, unsure as to why, but removing all usage of Autofac fixed the issue.
Very anticlimactic solution, but issue fixed...
Now the issue is to figure out why Autofac was behaving this way, all Debugging showed that the classes were created each request... but that is another question.

Set InArgument when launching a workflow programmatically

Is there any way to set the value of a workflow's InArgument parameter from another workflow when launching it programmatically ?
Here's how I launch it:
var req = new ExecuteWorkflowRequest { WorkflowId = new Guid(WorkflowGuids.RenewalWorkflowId), EntityId = theContact.Id };
service.Execute(req);
I can catch the EntityId value back in the other workflow in context.PrimaryEntityId but I am at a loss as to how to populated the arguments and retrieve them on the other side.
Is this possible ? Thanks.
InArgument are defined at step level, not at workflow level.
When a workflow is executed (by a trigger, on-demand or by code) you have the record Id.
You can create a custom workflow activity to fetch other data related (or not connected at all) with your record Id and make it as OutArgument so will be available as input for the InArgument you want to set.

send additional parameters to breeze-saving-server functions

I work in durandal project.
I use breeze to retrieve and save my data.
I want to send to the server, on saving, additional parameters other than the entity, like- who is the user that save the entity.
but, function saveChanges of breeze accept only one parameter- entities array for saving.
what can I do?
You can use the SaveOptions.tag property. Something like this:
var so = new SaveOptions({ resourceName: "SaveWithComment", tag: "Whatever data you want" });
return myEntityManager.saveChanges(null, so);
The 'tag' property is made available on the server within the ContextProvider, so you can access it like this:
// within your server side ContextProvider
protected override bool BeforeSaveEntity(EntityInfo entityInfo) {
var tag = (string)SaveOptions.Tag;
...
}

Categories

Resources