/// <summary> /// Filters the query by specialties in use. /// </summary> /// <param name="query">The query.</param> /// <param name="request">The request.</param> /// <param name="entityContext">The entity context.</param> /// <returns></returns> public static IQueryable<Specialty> FilterBySpecialtiesInUse(this IQueryable<Specialty> query, SearchSpecialtyRequest request, IEntityContext entityContext) { if (request.OnlyInUseSpecialties) { query = (from q in query join ps in entityContext.EntitySet<ProviderSpecialty>() on q.Id equals ps.SpecialtyId select q); } else { query = (from q in query where q.IsEnabled select q); } return query; }
private static void CreatePaymentOperationRecord(string request, string accountNum, string securityCode, string responseCode, string transactionId, int? configurationId, UserContext userContext, IEntityContext entityContext) { if (userContext == null || entityContext == null) return; // Mask credit card number/security code from logged operation details var accountNumSanitized = "XXXX" + accountNum.Substring(accountNum.Length - 4, 4); request = request.Replace(accountNum, accountNumSanitized); request = request.Replace("=" + securityCode + "&", "=XXXX&"); PaymentProcessorOperation operation = new PaymentProcessorOperation { ClientIP = userContext.ClientIP, Url = userContext.Uri.ToString(), UserName = userContext.UserName, ApiMethod = string.Empty, ResponseCode = responseCode, CorrelationId = Guid.NewGuid().ToString(), ErrorCode = string.Empty, LongMessage = request, ShortMessage = string.Empty, OperationDate = DateTime.UtcNow, TransactionId = transactionId, PaymentProcessorName = "PayFlowPro", PaymentProcessorConfigurationId = configurationId }; entityContext.EntitySet<PaymentProcessorOperation>().Add(operation); entityContext.SaveChanges(); }
private static IDbSet<ApplicationSetting> GetSettingsObjectSet(IEntityContext context) { return context.EntitySet<ApplicationSetting>(); }
private static void UpdateRoles(IEntityContext context, UpdateStaffProfileRequest request, StaffProfile staffProfile) { List<int> newRoleIds = null; if (request.RoleIds != null) { newRoleIds = request.RoleIds.ToList(); EnsureStaffRoleAdded(context, newRoleIds); } if (newRoleIds != null) { var userRoleSet = context.EntitySet<UserRole>(); var existingRoleIds = staffProfile.User.UserRoles.Select(ur => ur.Role.Id).ToList(); foreach (var existingRoleId in existingRoleIds) { if (!newRoleIds.Contains(existingRoleId)) { var existingUserRole = staffProfile.User.UserRoles.Single(ur => ur.Role.Id == existingRoleId); staffProfile.User.UserRoles.Remove(existingUserRole); userRoleSet.Remove(existingUserRole); } } foreach (var newRoleId in newRoleIds) { if (!existingRoleIds.Contains(newRoleId)) { var newRole = context.EntitySet<Role>().Find(newRoleId); staffProfile.User.AddRole(newRole); } } } }
private static void UpdatePermissions(IEntityContext context, UpdateStaffProfileRequest request, StaffProfile staffProfile) { if (request.Permissions == null) return; var permissionSet = context.EntitySet<StaffProfileOrgUnitPermission>(); foreach (var staffProfileOrgUnit in staffProfile.StaffProfileOrgUnits) { var permissionsForOrgUnit = request.Permissions.Where(p => p.OrgUnitId == staffProfileOrgUnit.OrgUnitId); if (!permissionsForOrgUnit.Any()) { foreach (var permissionToRemove in staffProfileOrgUnit.StaffProfileOrgUnitPermissions.ToList()) { permissionSet.Remove(permissionToRemove); } continue; } foreach (var existingPermission in staffProfileOrgUnit.StaffProfileOrgUnitPermissions.ToList()) { if (!permissionsForOrgUnit.Select(p => p.StaffPermissionValue).Contains(existingPermission.StaffPermissionValue)) { permissionSet.Remove(existingPermission); } else { var updatedPermission = permissionsForOrgUnit.Single(p => p.StaffPermissionValue == existingPermission.StaffPermissionValue); existingPermission.IsGranted = updatedPermission.IsGranted; existingPermission.AppliesToDescendants = updatedPermission.AppliesToDescendants; } } var permissionsToAdd = permissionsForOrgUnit.Where(p => !staffProfileOrgUnit.StaffProfileOrgUnitPermissions.Select(ep => ep.StaffPermissionValue).Contains(p.StaffPermissionValue)); foreach (var newPermission in permissionsToAdd) { var staffProfileOrgUnitPermission = new StaffProfileOrgUnitPermission { AppliesToDescendants = newPermission.AppliesToDescendants, IsGranted = newPermission.IsGranted, StaffPermissionValue = newPermission.StaffPermissionValue }; staffProfileOrgUnit.StaffProfileOrgUnitPermissions.Add(staffProfileOrgUnitPermission); } } }
private static void UpdateOrgUnits(IEntityContext context, UpdateStaffProfileRequest request, StaffProfile staffProfile) { if (request.OrgUnitIds != null) { var staffProfileOrgUnitObjectSet = context.EntitySet<StaffProfileOrgUnit>(); var staffProfileOrgUnitPermissionsObjectSet = context.EntitySet<StaffProfileOrgUnitPermission>(); var existingOrgUnits = staffProfile.StaffProfileOrgUnits.ToList(); foreach (var orgUnit in existingOrgUnits) { if (!request.OrgUnitIds.Any(o => o == orgUnit.OrgUnitId)) { var permissions = orgUnit.StaffProfileOrgUnitPermissions.ToList(); foreach (var permission in permissions) { orgUnit.StaffProfileOrgUnitPermissions.Remove(permission); staffProfileOrgUnitPermissionsObjectSet.Remove(permission); } staffProfile.StaffProfileOrgUnits.Remove(orgUnit); staffProfileOrgUnitObjectSet.Remove(orgUnit); } } foreach (int id in request.OrgUnitIds) { if (!staffProfile.StaffProfileOrgUnits.Any(o => o.OrgUnitId == id)) { staffProfile.StaffProfileOrgUnits.Add(new StaffProfileOrgUnit { OrgUnitId = id, StaffProfileId = staffProfile.Id }); } } } }
private static void EnsureStaffRoleAdded(IEntityContext context, IList<int> roleIds) { var staffRole = context.EntitySet<Role>().FirstOrDefault(r => r.RoleName == RolesConstants.ContentManager); if (staffRole != null && !roleIds.Contains(staffRole.Id)) roleIds.Add(staffRole.Id); }