Esempio n. 1
0
        public async Task <CommandResult> Handler(CreateMigrateCompanyCommand command)
        {
            if (!command.Validated())
            {
                return(new CommandResult(false, "Error migrate company", command.Notifications));
            }

            if (await _companyRepository.ExistCnpj(command.Cnpj))
            {
                AddNotification("Cnpj", "Cnpj already registered");
                return(new CommandResult(false, "Error migrate company", Notifications));
            }


            if (await _companyRepository.ExistEmail(command.Email))
            {
                AddNotification("Email", "Email already registered");
                return(new CommandResult(false, "Error migrate company", Notifications));
            }

            var company = new Company(
                new Document().DocumentCnpj(command.Cnpj),
                new Email(command.Email),
                new Name(command.FirstName, command.LastName),
                new Phone(command.FixPhone, command.MobilePhone),
                command.CompanyTracking,
                ETypeCompany.MigrateCompany
                );

            await _companyRepository.Save(company);

            var response = new MigrateCompanyCommandResponse(
                company.Id.ToString(),
                company.Document.Cnpj,
                company.Email.Address,
                company.Name.GetFullName(),
                company.Phone.FixNumber,
                company.Phone.MobileNumber,
                company.CompanyTracking,
                company.CreateAt);

            return(new CommandResult(true, "migrated company successfully.", response));
        }
Esempio n. 2
0
        public async Task <CommandResult> GetMigrateCompanyByEmail(string email)
        {
            var company = await _companyRepository.GetCompanyByEmail(email);

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

            var result = new MigrateCompanyCommandResponse(
                company.Id.ToString(),
                company.Document.Cnpj,
                company.Email.Address,
                company.Name.GetFullName(),
                company.Phone.FixNumber,
                company.Phone.MobileNumber,
                company.CompanyTracking,
                company.CreateAt
                );

            return(new CommandResult(true, "migrate company", result));
        }