public async Task <ApplicationDataPolicyModel> UpdateAsync(ApplicationDataPolicyModel applicationDataPolicy) { a3SContext.Entry(applicationDataPolicy).State = EntityState.Modified; await a3SContext.SaveChangesAsync(); return(applicationDataPolicy); }
public async Task <ApplicationDataPolicyModel> CreateAsync(ApplicationDataPolicyModel applicationDataPolicy) { a3SContext.ApplicationDataPolicy.Add(applicationDataPolicy); await a3SContext.SaveChangesAsync(); return(applicationDataPolicy); }
private async Task AssignApplicationDataPoliciesToSubRealmFromApplicationDataPolicyIdListAsync(SubRealmModel subRealm, List <Guid> applicationDataPolicyIds, Guid changedById) { // We want to track which permissions were added so that their changedById can be updated, but leave the permissions that already exist un-touched. List <SubRealmApplicationDataPolicyModel> newApplicationDataPolicyState = new List <SubRealmApplicationDataPolicyModel>(); foreach (var applicationDataPolicyId in applicationDataPolicyIds) { // Search existing sub-realm permissions state for the permission. var existingSubRealmApplicationDataPolicy = subRealm.SubRealmApplicationDataPolicies.FirstOrDefault(SubRealmApplicationDataPolicyModel => SubRealmApplicationDataPolicyModel.ApplicationDataPolicyId == applicationDataPolicyId); if (existingSubRealmApplicationDataPolicy != null) { newApplicationDataPolicyState.Add(existingSubRealmApplicationDataPolicy); continue; } // If the application data policy is new, attempt to add it, but perform some checks first. ApplicationDataPolicyModel existingApplicationDataPolicy = await applicationDataPolicyRepository.GetByIdAsync(applicationDataPolicyId); if (existingApplicationDataPolicy == null) { throw new ItemNotFoundException($"Application Data Policy with ID '{applicationDataPolicyId}' not found when attempting to assign it to a sub-realm."); } newApplicationDataPolicyState.Add(new SubRealmApplicationDataPolicyModel { ApplicationDataPolicy = existingApplicationDataPolicy, SubRealm = subRealm, ChangedBy = changedById }); // If a permission was added, it indicates that parent sub-realm was changed. subRealm.ChangedBy = changedById; } subRealm.SubRealmApplicationDataPolicies = newApplicationDataPolicyState; }
public async Task DeleteAsync(ApplicationDataPolicyModel applicationDataPolicy) { a3SContext.ApplicationDataPolicy.Remove(applicationDataPolicy); await a3SContext.SaveChangesAsync(); }