public async Task <UserDeleteResponse> DeleteOne(ApplicationUser currentUser, UserTypeVM userType, long id) { var response = new UserDeleteResponse(); var applicationUserType = GetApplicationUserType(currentUser); if (applicationUserType != UserType.Admin && applicationUserType != UserType.Manager) // удалить может только админ или менеджер { response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_DELETE_USER]); return(response); } if (applicationUserType == UserType.Manager && userType == UserTypeVM.Admin) // менеджер хочет удалить админа { response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_DELETE_USER]); return(response); } var applicationUserValue = await ApplicationUserFactory.GetApplicationUserAsync(_fuelContext, userType, id); if (applicationUserValue == null) { response.AddError(_stringLocalizer[CustomStringLocalizer.USER_NOT_FOUND]); return(response); } var result = await _userManager.DeleteAsync(applicationUserValue); response.IsSuccess = result.Succeeded; return(response); }
public async Task <UserUpdateResponse> PostOne(ApplicationUser currentUser, UserTypeVM userType, ApplicationUserVM applicationUserVM) { var response = new UserUpdateResponse(); var applicationUserType = GetApplicationUserType(currentUser); if (applicationUserType != UserType.Admin && applicationUserType != UserType.Manager) // редактировать может только админ или менеджер { response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_ADD_OR_UPDATE_USER]); return(response); } if (applicationUserType == UserType.Manager && userType == UserTypeVM.Admin) // менеджер хочет редактировать админа { response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_ADD_OR_UPDATE_USER]); return(response); } ApplicationUser applicationUserValue = null; if (applicationUserVM.Id.HasValue) { applicationUserValue = await ApplicationUserFactory.GetApplicationUserAsync(_fuelContext, userType, applicationUserVM.Id.Value); } if (applicationUserValue == null) { response.AddError(_stringLocalizer[CustomStringLocalizer.USER_NOT_FOUND]); return(response); } applicationUserValue.Email = applicationUserVM.Email; applicationUserValue.UserName = applicationUserVM.Email; var result = await _userManager.UpdateAsync(applicationUserValue); if (!result.Succeeded) { response.AddError(_stringLocalizer[CustomStringLocalizer.USER_NOT_FOUND]); return(response); } await UpdateUserClaimsAsync(applicationUserVM, applicationUserValue).ConfigureAwait(false); response.Id = applicationUserValue.Id; return(response); }