Exemple #1
0
        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));
        }
Exemple #2
0
        public async Task <CommandResult> GetNewCompanyByEmail(string email)
        {
            var company = await _companyRepository.GetCompanyByEmail(email);

            if (company == null)
            {
                return(new CommandResult(false, "not found.", null));
            }

            var result = 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, "new company", result));
        }