public void Execute(IDeleteUserModel userModel) { RemoveExistingUserRoles(userModel.UserId); RemoveExistingUserOdsInstanceRegistrations(userModel.UserId); _identity.Users.Remove(_identity.Users.Single(x => x.Id == userModel.UserId)); _identity.SaveChanges(); }
private void RemoveExistingUserOdsInstanceRegistrations(int odsInstanceId) { var existingUserOdsInstanceRegistrations = _identity.UserOdsInstanceRegistrations.Where(x => x.OdsInstanceRegistrationId == odsInstanceId); if (existingUserOdsInstanceRegistrations.Any()) { _identity.UserOdsInstanceRegistrations.RemoveRange(existingUserOdsInstanceRegistrations); } _identity.SaveChanges(); }
private static void RemoveExistingUserRoles(string userId, AdminAppIdentityDbContext dbContext) { var existingUserRoles = dbContext.Set <IdentityUserRole>().Where(x => x.UserId == userId); if (existingUserRoles.Any()) { dbContext.Set <IdentityUserRole>().RemoveRange(existingUserRoles); } dbContext.SaveChanges(); }
private static void RemoveExistingUserOdsInstanceRegistrations(string userId, AdminAppIdentityDbContext dbContext) { var existingUserOdsInstanceRegistrations = dbContext.UserOdsInstanceRegistrations.Where(x => x.UserId == userId); if (existingUserOdsInstanceRegistrations.Any()) { dbContext.UserOdsInstanceRegistrations.RemoveRange(existingUserOdsInstanceRegistrations); } dbContext.SaveChanges(); }
public void Execute(IEditUserRoleModel model) { var newUserRole = new IdentityUserRole { UserId = model.UserId, RoleId = model.RoleId }; var currentUserRole = _identity.UserRoles.SingleOrDefault(x => x.UserId == model.UserId); if (currentUserRole != null) { _identity.UserRoles.Remove(currentUserRole); } _identity.UserRoles.Add(newUserRole); _identity.SaveChanges(); }
public async Task <int> Execute(IRegisterOdsInstanceModel instance, ApiMode mode, string userId, CloudOdsClaimSet cloudOdsClaimSet = null) { var instanceName = InferInstanceDatabaseName(instance.NumericSuffix.Value, mode); var newInstance = new OdsInstanceRegistration { Name = instanceName, Description = instance.Description }; await _odsInstanceFirstTimeSetupService.CompleteSetup(newInstance, cloudOdsClaimSet, mode); _identity.UserOdsInstanceRegistrations.Add( new UserOdsInstanceRegistration { OdsInstanceRegistrationId = newInstance.Id, UserId = userId }); _identity.SaveChanges(); return(newInstance.Id); }
public void Execute(IEditOdsInstanceRegistrationForUserModel model) { var preexistingAssociations = _identity.UserOdsInstanceRegistrations.Where(x => x.UserId == model.UserId).ToList(); var selectedOdsInstanceRegistrationIds = model.OdsInstanceRegistrations.Where(x => x.Selected).Select(x => x.OdsInstanceRegistrationId).ToList(); var recordsToAdd = NewAssignments(model.UserId, selectedOdsInstanceRegistrationIds, preexistingAssociations); if (recordsToAdd.Any()) { _identity.UserOdsInstanceRegistrations.AddRange(recordsToAdd); } var recordsToRemove = AssignmentsToRemove(selectedOdsInstanceRegistrationIds, preexistingAssociations); if (recordsToRemove.Any()) { _identity.UserOdsInstanceRegistrations.RemoveRange(recordsToRemove); } _identity.SaveChanges(); }