public async Task <SmartHomeValidationResult> CreateUserAsync(CreateUserModel model) { var validationResult = await ValidateAsync(model); if (!validationResult.Succeeded) { return(validationResult); } return(SmartHomeValidationResult.FromIdentityResult(await repository.CreateUserAsync(model))); }
public async Task <SmartHomeValidationResult> ChangePasswordAsync(ChangePasswordModel changePasswordModel) { var errors = Validate(changePasswordModel); if (!errors.Succeeded) { return(errors); } return(SmartHomeValidationResult.FromIdentityResult(await repository.ChangePasswordAsync(changePasswordModel))); }
public async Task <SmartHomeValidationResult> AddToOrRemoveFromRolesAsync(long userId, IEnumerable <long> roleIds) { var allUserRoles = await roleRepository.GetUserRolesAsync(userId); var rolesToAdd = roleIds.Except(allUserRoles.Select(x => x.Id)).ToList(); // roles that user currently has without those sent to the server var rolesToRemove = allUserRoles.Select(x => x.Id).Except(roleIds).ToList(); if (rolesToAdd.Count > 0 || rolesToRemove.Count > 0) { var validationResult = SmartHomeValidationResult.FromIdentityResult(await repository.AddToRolesAsync(userId, rolesToAdd)); validationResult = validationResult.Merge(SmartHomeValidationResult.FromIdentityResult( await repository.RemoveFromRolesAsync(userId, rolesToRemove))); return(validationResult); } return(SmartHomeValidationResult.Success); }
public async Task <SmartHomeValidationResult> CreateRoleAsync(CreateRoleModel model) { return(SmartHomeValidationResult.FromIdentityResult(await roleRepository.CreateRoleAsync(model))); }
public async Task <SmartHomeValidationResult> DeleteUserAsync(long id) { return(SmartHomeValidationResult.FromIdentityResult(await repository.DeleteUserAsync(id))); }
public async Task <SmartHomeValidationResult> UpdateUserAsync(UserModel model) { return(SmartHomeValidationResult.FromIdentityResult(await repository.UpdateUserAsync(model))); }