public async Task <CommandResult> Handler(CreateNewCompanyCommand command) { if (!command.Validated()) { return(new CommandResult(false, "Error creating new company", command.Notifications)); } if (await _companyRepository.ExistCpf(command.Cpf)) { AddNotification("Cpf", "Cpf already registered"); return(new CommandResult(false, "Error creating new company", Notifications)); } if (await _companyRepository.ExistEmail(command.Email)) { AddNotification("Email", "Email already registered"); return(new CommandResult(false, "Error creating new company", Notifications)); } var company = new Company( new Document().DocumentCpf(command.Cpf), new Email(command.Email), new Name(command.FirstName, command.LastName), new Phone(command.FixPhone, command.MobilePhone), command.CompanyTracking, ETypeCompany.NewCompany ); await _companyRepository.Save(company); var response = new NewCompanyCommandResponse( company.Id.ToString(), company.Document.Cpf, company.Email.Address, company.Name.GetFullName(), company.Phone.FixNumber, company.Phone.MobileNumber, company.CompanyTracking, company.CreateAt); return(new CommandResult(true, "company successfully registered", response)); }
public async Task <IActionResult> CreateNewCompany([FromBody] CreateNewCompanyCommand command) { var result = await _companyHandler.Handler(command); return(result.Success ? Ok(result) : StatusCode(406, result)); }