Skip to content

Commit

Permalink
Merge pull request #73 from DynamicsValue/feature/25x-improvements
Browse files Browse the repository at this point in the history
Change bulk operations implementation to use internal operations that…
  • Loading branch information
jordimontana82 authored May 26, 2024
2 parents e17aa73 + d879715 commit 619c0e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContex

foreach (var record in records)
{
var id = service.Create(record);
var id = ctx.CreateEntity(record);
createdIds.Add(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContex

foreach (var record in records)
{
service.Update(record);
ctx.UpdateEntity(record);
}

return new UpdateMultipleResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,23 @@ public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContex

var service = ctx.GetOrganizationService();

foreach (var record in records)
foreach (var record in records)
{
var response = service.Execute(new UpsertRequest() { Target = record }) as UpsertResponse;
UpsertResponse response = null;
if (ctx.ContainsEntity(record.LogicalName, record.Id))
{
ctx.UpdateEntity(record);
response = new UpsertResponse();
response.Results.Add("RecordCreated", false);
response.Results.Add("Target", new EntityReference(record.LogicalName, record.Id));
}
else
{
var id = ctx.CreateEntity(record);
response = new UpsertResponse();
response.Results.Add("RecordCreated", true);
response.Results.Add("Target", new EntityReference(record.LogicalName, id));
}
results.Add(response);
}

Expand Down

0 comments on commit 619c0e7

Please sign in to comment.