public async ValueTask <Result> ExecuteAsync(UserUpdate operation, CancellationToken cancellation = default) { var scope = _logger.BeginScope("Updating user. [UserId: {userId}]", operation.Id); try { var root = await _store.GetAsync(operation.Id, cancellation); if (root == null) { _logger.LogInformation("User not found"); return(DomainError.UserError.UserNotFound); } if (root.Update(operation.FirstName, operation.LastNames, operation.BirthDate) is ErrorResult error) { _logger.LogInformation("Error [ErrorCode: {errorCode}]", error.ErrorCode); return(error); } await _store.SaveAsync(root, cancellation); _logger.LogInformation("User updated with success"); return(Result.Ok(_mapper.Map((Domain.Common.User)root.State))); } catch (Exception e) { _logger.LogError(e, "Exception: ", operation.Id); return(Result.Fail(e)); } finally { scope.Dispose(); } }
public async ValueTask <Result> ExecuteAsync(AddressRemove operation, CancellationToken cancellation = default) { var scope = _logger.BeginScope("Remove Address. [UserId: {0}]", operation.UserId); try { var root = await _store.GetAsync(operation.UserId, cancellation); if (root == null) { _logger.LogInformation("User not found"); return(DomainError.UserError.UserNotFound); } if (root.RemoveAddress(operation.Id) is ErrorResult error) { _logger.LogInformation("Error [ErrorCode: {0}]", error.ErrorCode); return(error); } await _store.SaveAsync(root, cancellation); _logger.LogInformation("Address removed with success"); return(Result.Ok()); } catch (Exception e) { _logger.LogError(e, "Exception: "); return(Result.Fail(e)); } finally { scope.Dispose(); } }
public async ValueTask <Result> ExecuteAsync(AddressAdd operation, CancellationToken cancellation = default) { var scope = _logger.BeginScope("Get Address. [UserId: {userId}]", operation.UserId); try { var root = await _store.GetAsync(operation.UserId, cancellation); if (root == null) { _logger.LogInformation("User not found"); return(DomainError.UserError.UserNotFound); } if (root.AddAddress(operation.Line, operation.Number, operation.PostCode) is ErrorResult error) { _logger.LogInformation("Error. [ErrorCode: {errorCode}].", error.ErrorCode); return(error); } await _store.SaveAsync(root, cancellation); _logger.LogInformation("Address added with success"); var address = root.State.Addresses.Last(); return(Result.Ok(_mapper.Map(address))); } catch (Exception e) { _logger.LogError(e, "Exception: "); return(Result.Fail(e)); } finally { scope.Dispose(); } }
public async ValueTask <Result> ExecuteAsync(UserAdd operation, CancellationToken cancellation = default) { var scope = _logger.BeginScope("Creating user."); try { var root = _store.Create(); if (root.Create(operation.Email, operation.FirstName, operation.LastNames, operation.BirthDate) is ErrorResult error) { _logger.LogInformation("Error [ErrorCode: {errorCode}]", error.ErrorCode); return(error); } if (await _repository.EmailExistAsync(operation.Email, cancellation)) { _logger.LogInformation("Email already exist"); return(DomainError.UserError.EmailAlreadyExist); } await _store.SaveAsync(root, cancellation); _logger.LogInformation("User created: [UserId: {userId}]", root.State.Id); return(Result.Ok(_mapper.Map((Domain.Common.User)root.State))); } catch (Exception e) { _logger.LogError(e, "Exception: "); return(Result.Fail(e)); } finally { scope.Dispose(); } }