public IActionResult RegisterUser(RegisterUserDto registerUserDto) { var firstName = FirstName.Create(registerUserDto.FirstName); var lastName = LastName.Create(registerUserDto.LastName); var email = Email.Create(registerUserDto.Email); var password = Password.Create(registerUserDto.Password); Result resultValidation = Result.Combine(firstName, lastName, email, password); if (resultValidation.IsFailure) { return(Error(resultValidation.Error)); } var query = new CheckDuplicateEmailQuery((Application.Users.Queries.Email)email.Value.Value); Result resultQuery = _messages.Dispatch(query); if (resultQuery.IsFailure) { return(Error(resultQuery.Error)); } var command = new RegisterUserCommand(firstName.Value, lastName.Value, email.Value, password.Value); Result result = _messages.Dispatch(command); return(FromResultCreated(result)); }
/// <inheritdoc /> public async Task <Result <TokenResponse> > Handle(CreateUserCommand request, CancellationToken cancellationToken) { Result <FirstName> firstNameResult = FirstName.Create(request.FirstName); Result <LastName> lastNameResult = LastName.Create(request.LastName); Result <Email> emailResult = Email.Create(request.Email); Result <Password> passwordResult = Password.Create(request.Password); Result firstFailureOrSuccess = Result.FirstFailureOrSuccess(firstNameResult, lastNameResult, emailResult, passwordResult); if (firstFailureOrSuccess.IsFailure) { return(Result.Failure <TokenResponse>(firstFailureOrSuccess.Error)); } if (!await _userRepository.IsEmailUniqueAsync(emailResult.Value)) { return(Result.Failure <TokenResponse>(DomainErrors.User.DuplicateEmail)); } string passwordHash = _passwordHasher.HashPassword(passwordResult.Value); var user = User.Create(firstNameResult.Value, lastNameResult.Value, emailResult.Value, passwordHash); _userRepository.Insert(user); await _unitOfWork.SaveChangesAsync(cancellationToken); string token = _jwtProvider.Create(user); return(Result.Success(new TokenResponse(token))); }
static void Main(string[] args) { using (TestDbContext db = new TestDbContext()) { #region Step1 db.Database.EnsureDeleted(); db.Database.EnsureCreated(); db.Applicants.Add(new Applicant(new FullName(FirstName.Create("Amila"), LastName.Create("Udayanga")))); var person = new Person(new FullName(FirstName.Create("Amila"), LastName.Create("Udayanga"))); person.Address = new Address { Line1 = "Line1", Line2 = "Line2" }; db.People.Add(person); db.SaveChanges(); #endregion } using (TestDbContext db = new TestDbContext()) { #region Step2 var people = db.People.FirstOrDefault(); var applicants = db.Applicants.ToList(); var addresses = db.Addresses.ToList(); #endregion } }
/// <inheritdoc /> public async Task <Result> Handle(UpdateUserCommand request, CancellationToken cancellationToken) { if (request.UserId != _userIdentifierProvider.UserId) { return(Result.Failure(DomainErrors.User.InvalidPermissions)); } Result <FirstName> firstNameResult = FirstName.Create(request.FirstName); Result <LastName> lastNameResult = LastName.Create(request.LastName); Result firstFailureOrSuccess = Result.FirstFailureOrSuccess(firstNameResult, lastNameResult); if (firstFailureOrSuccess.IsFailure) { return(Result.Failure(firstFailureOrSuccess.Error)); } Maybe <User> maybeUser = await _userRepository.GetByIdAsync(request.UserId); if (maybeUser.HasNoValue) { return(Result.Failure(DomainErrors.User.NotFound)); } User user = maybeUser.Value; user.ChangeName(firstNameResult.Value, lastNameResult.Value); await _unitOfWork.SaveChangesAsync(cancellationToken); return(Result.Success()); }
public void Create_WithError() { Result <Person> personResult = Create.From(Person.Create, Create.From(Name.Create, FirstName.Create("John"), LastName.Create("Doe")), EMail.Create("*****@*****.**")); }
public void Create_Successfully() { Result <Person> personResult = Create.From(Person.Create, Create.From(Name.Create, FirstName.Create("John"), LastName.Create("Miller")), EMail.Create("*****@*****.**")); }
private ContactRM CreateContactForAssociate(Commands.V1.Contact.CreateForAssociate cmd) { Contact contact = Contact.Create(_contacts++, cmd.PrimaryAddressId, cmd.IsActive, cmd.PrimaryEmailId, cmd.PrimaryPhoneId, FirstName.Create(cmd.FirstName), LastName.Create(cmd.LastName), Title.Create(cmd.Title)); _repository.AddContactForAssociate(contact, cmd.AssociateId); return(Conversions.GetContactRM(contact)); }