Ejemplo n.º 1
0
        public async Task <SmartHomeValidationResult> CreateUserAsync(CreateUserModel model)
        {
            var validationResult = await ValidateAsync(model);

            if (!validationResult.Succeeded)
            {
                return(validationResult);
            }

            return(SmartHomeValidationResult.FromIdentityResult(await repository.CreateUserAsync(model)));
        }
Ejemplo n.º 2
0
        public async Task <SmartHomeValidationResult> ChangePasswordAsync(ChangePasswordModel changePasswordModel)
        {
            var errors = Validate(changePasswordModel);

            if (!errors.Succeeded)
            {
                return(errors);
            }

            return(SmartHomeValidationResult.FromIdentityResult(await repository.ChangePasswordAsync(changePasswordModel)));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public async Task <SmartHomeValidationResult> CreateRoleAsync(CreateRoleModel model)
 {
     return(SmartHomeValidationResult.FromIdentityResult(await roleRepository.CreateRoleAsync(model)));
 }
Ejemplo n.º 5
0
 public async Task <SmartHomeValidationResult> DeleteUserAsync(long id)
 {
     return(SmartHomeValidationResult.FromIdentityResult(await repository.DeleteUserAsync(id)));
 }
Ejemplo n.º 6
0
 public async Task <SmartHomeValidationResult> UpdateUserAsync(UserModel model)
 {
     return(SmartHomeValidationResult.FromIdentityResult(await repository.UpdateUserAsync(model)));
 }