public ApplicationResult <UserDto> Create(UserCreationDto userDto) { var userEdit = UserEdit.Create(userDto.ExternalId, userDto.UserName, userDto.FullName, userDto.Email); var brokenRules = userEdit.GetBrokenValidationRules(); if (!brokenRules.IsValid) { return new ApplicationResult <UserDto> { Errors = brokenRules.Errors.ToList(), IsSuccessful = false, IsFailure = true } } ; userEdit = _userRepository.Create(userEdit); if (userDto.Keys.Any()) { foreach (var key in userDto.Keys) { var keyEdit = KeyEdit.Create(userEdit, key.Password); _userRepository.CreateKey(userEdit.Id, keyEdit); } } UnitOfWork.Commit(); return(new ApplicationResult <UserDto>() { Data = Mapper.Map <UserDto>(userEdit), IsSuccessful = true, IsFailure = false }); }
public ApplicationResult <KeyDto> CreateKey(Guid userId, KeyCreationDto keyDto) { var userEdit = _userRepository.Get(userId); var passwordEncrypted = _passwordCryptographer.Encrypt(keyDto.Password); var keyEdit = KeyEdit.Create(userEdit, passwordEncrypted); var brokenRules = keyEdit.GetBrokenValidationRules(); if (!brokenRules.IsValid) { return new ApplicationResult <KeyDto>() { Errors = brokenRules.Errors.ToList(), IsFailure = true } } ; userEdit.CreateKey(keyEdit); _userRepository.CreateKey(keyEdit.Id, keyEdit); UnitOfWork.Commit(); return(new ApplicationResult <KeyDto>() { Data = Mapper.Map <KeyDto>(keyEdit), IsSuccessful = true }); }
public virtual void DeleteKey(KeyEdit key) { if (key.Status == EKeyStatus.Active) { AddBrokenValidationRule(new ValidationFailure(nameof(Status), UserMessages.ErrorRuleKeyIsActive)); } var keyFound = _keys.Find(new KeyExistsByKeySpec(key).IsSatisfiedBy); _keys.Remove(keyFound); DomainEvents.Raise(new KeyRemovedEvent() { Key = keyFound }); }
public KeyEdit CreateKey(KeyEdit key) { var existKeyActive = Keys.Any(x => x.Status == EKeyStatus.Active); if (!existKeyActive) { AddBrokenValidationRule(new ValidationFailure(nameof(Status), UserMessages.ErrorRuleKeyActiveExists)); } else { _keys.Add(key); DomainEvents.Raise(new KeyAddedEvent() { Key = key }); } return(key); }
public KeyEdit UpdateKey(Guid userId, KeyEdit keyEdit) { var key = _umsDbContext.Keys.Update(keyEdit); return(key.Entity); }