Skip to content

Commit

Permalink
S20 facility permission (#186)
Browse files Browse the repository at this point in the history
* Update FDR and Payment Line Security

* Change plugin to custom workflow activity to generate facility permissions for contact
  • Loading branch information
pallvigrover authored Jul 18, 2024
1 parent ccbdcc7 commit 98c9a72
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using ECC.Core.DataContext;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System;
using System.Activities;
using System.Linq;

namespace OFM.Infrastructure.CustomWorkflowActivities.Contact
{
public sealed class GenerateFacilityPermissions : CodeActivity
{
[ReferenceTarget("account")]
[RequiredArgument]
[Input("ParentCustomerID")]
public InArgument<EntityReference> parentCustomerID { get; set; }

protected override void Execute(CodeActivityContext executionContext)
{
ITracingService tracingService = executionContext.GetExtension<ITracingService>();
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
//Create an Organization Service
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: GenerateFacilityPermissions", DateTime.Now.ToLongTimeString());
var organizationID = this.parentCustomerID.Get(executionContext);
using (var crmContext = new DataverseContext(service))
{
var oldPermissions = crmContext.ofm_bceid_facilitySet.Where(permission => permission.ofm_bceid.Id == context.PrimaryEntityId).ToList();
tracingService.Trace($"Total Old permissions count {oldPermissions.Count}");

oldPermissions.ForEach(record =>
{
if (record.Attributes.Contains(ofm_bceid_facility.Fields.statuscode))
{
var entity = new ofm_bceid_facility
{
Id = record.Id,
statecode = ofm_bceid_facility_statecode.Inactive,
statuscode = ofm_bceid_facility_StatusCode.Inactive
};

UpdateRequest updateRequest = new UpdateRequest { Target = entity };
crmContext.Execute(updateRequest);

}
});

var newFacilityPermissions = crmContext.AccountSet.Where(facility => facility.parentaccountid.Id == organizationID.Id).ToList();
tracingService.Trace($"Total New child facilities count {newFacilityPermissions.Count}");

newFacilityPermissions.ForEach(record =>
{
if (record.Attributes.Contains(Account.Fields.statuscode) &&
record.GetAttributeValue<OptionSetValue>(Account.Fields.statuscode).Value == Convert.ToInt32(Account_StatusCode.Active))
{
var entity = new ofm_bceid_facility
{
ofm_bceid = new EntityReference(ECC.Core.DataContext.Contact.EntityLogicalName, context.PrimaryEntityId),
ofm_facility = new EntityReference(Account.EntityLogicalName, record.Id)
};

CreateRequest createRequest = new CreateRequest { Target = entity };
crmContext.Execute(createRequest);
}
});

tracingService.Trace("Completed with no errors.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
<EmbeddedResource Remove="Properties\**" />
<None Remove="Properties\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Contact\GenerateFacilityPermissions.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="packages.config" />
</ItemGroup>
Expand Down
89 changes: 0 additions & 89 deletions OFM.Infrastructure.Plugins/Contact/GenerateFacilityPermissions.cs

This file was deleted.

0 comments on commit 98c9a72

Please sign in to comment.