public ApplicationResult <KeyDto> UpdateKey(Guid userId, KeyUpdateDto keyDto) { var userFound = _userRepository.Get(userId); var keyEdit = Mapper.Map <KeyEdit>(keyDto); var passwordEncrypted = _passwordCryptographer.Encrypt(keyDto.Password); keyEdit.ChangePassword(passwordEncrypted); var brokenRules = keyEdit.GetBrokenValidationRules(); if (!brokenRules.IsValid) { return new ApplicationResult <KeyDto>() { Errors = brokenRules.Errors.ToList(), IsFailure = true } } ; _userRepository.UpdateKey(userId, keyEdit); UnitOfWork.Commit(); return(new ApplicationResult <KeyDto>() { Data = Mapper.Map <KeyDto>(keyEdit), IsSuccessful = true }); }
public IActionResult UpdateKeyForUser(Guid userId, Guid keyId, [FromBody] KeyUpdateDto key) { if (key == null) { return(BadRequest()); } var userFound = _userApplication.Get(userId).Data; if (userFound == null) { return(NotFound()); } var keyFound = _userApplication.GetKey(userId, keyId).Data; if (keyFound == null) { return(NotFound()); } var keyUpdated = _userApplication.UpdateKey(userId, key).Data; return(Ok(CreateLink(keyUpdated))); }