Exemple #1
0
        public string Execute(IList <string> commandParameters)
        {
            if (commandParameters == null)
            {
                throw new ArgumentNullException(Messages.InvalidCommandParametersErrorMessage);
            }

            string name, registrationNumber;

            try
            {
                name = commandParameters[0];
                registrationNumber = commandParameters[1];
            }
            catch (Exception)
            {
                throw new ArgumentException(Messages.InvalidCommandParametersErrorMessage);
            }

            var  company        = companyFactory.CreateCompany(name, registrationNumber);
            bool companyIsSaved = companyRepository.Commit(company);

            if (companyIsSaved)
            {
                return(string.Format(Messages.CompanyCreatedSuccessMessage, name));
            }

            throw new InvalidOperationException(string.Format(Messages.CompanyExistsErrorMessage, name));
        }
Exemple #2
0
        internal static string CreateCompanyMethod(string name, string registrationNumber,
                                                   ICompanyFactory companyFactory, IDictionary <string, ICompany> companies)
        {
            if (companies.ContainsKey(name))
            {
                return(string.Format(EngineConstants.CompanyExistsErrorMessage, name));
            }

            var company = companyFactory.CreateCompany(name, registrationNumber);

            companies.Add(name, company);

            return(string.Format(EngineConstants.CompanyCreatedSuccessMessage, name));
        }
Exemple #3
0
        public void Register(RegisterCompanyCommand command)
        {
            command.Validate();

            if (AddNotifications(command))
            {
                return;
            }

            Company company = _factory.CreateCompany(command.Name, command.Description, command.Email, command.Cnpj,
                                                     command.InscricaoEstadual, command.OwnerName, command.OwnerBirthday, command.OwnerCpf, _identityResolver.GetUserId());

            if (NotifyCnpjExists(company.Cnpj, company.Id))
            {
                return;
            }

            _repository.Register(company);

            if (Commit())
            {
                Publish(new RegisteredCompanyIntegrationEvent(company.Id, company.Email.Email, company.TenantId));
            }
        }