For adding new entity inside my custom API I use code like this:
var tagGroup = new Dictionary<string, object>();
tagGroup.Add("Title", "Some new tagGroup name");
App.Data.Create("TagGroup", tagGroup, "WebApiUser");
This work fine if I just need to add new entity, but If I need to do more operations and in this opetarions I need to use Id or Guid of this newly created entity I don't know how to get it.
One way is to get this new entity by its title back, but If this title is not unique I don't know how?
I try with this code:
dynamic obj1 = App.Data.Create("TagGroup", tagGroup, "Web Api User");
// or
var obj2 = App.Data.Create("TagGroup", tagGroup, "Web Api User");
But get error becouse function don't return any value.. Is there any other way how to make this work?
Is posible to define guid of new entity in advance like for IsPublished?
====================
Solution 1:
var tGuid = System.Guid.NewGuid().ToString();
tagGroup.Add("EntityGuid", tGuid);
and work OK
I am OK with solution to set EntityGuid in custom api controller to get new EntityId
var tGuid = System.Guid.NewGuid();
var tagGroup = new Dictionary<string, object>();
tagGroup.Add("Title", "Some new tagGroup name");
tagGroup.Add("EntityGuid", tGuid);
App.Data.Create("TagGroup", tagGroup, "WebApiUser");
var tNewObj =AsDynamic(App.Data["TagGroup"]).Where(x=>x.EntityGuid==tGuid).First();
var tNewEntityId = tNewObj.EntityId;
// do whatewer you want with this entity..
This is my final code...