Ejemplo n.º 1
0
        public ObjectRequest NewAddressCustomer(RegisterAddressCommand cmd)
        {
            var customer = _repCustomer.GetCustomer(cmd.CustomerId);

            if (customer == null)
            {
                return(new ObjectRequest()
                       .CreateObjectRequest($"Endereço nao foi adicionado, Cliente não Registrado no Sistema", false));
            }

            var address = new Address(cmd.Street, cmd.Number, cmd.Complement, cmd.District, cmd.City, cmd.State, cmd.CEP, cmd.CustomerId);

            _repAddress.AddEntity(address);

            if (Commit(address))
            {
                return(new ObjectRequest().CreateObjectRequest($" Novo Endereco Add com Sucesso", true));
            }

            return(new ObjectRequest().CreateErrorNotification(address.ListErrors()));
        }
Ejemplo n.º 2
0
        public ObjectRequest NewSupply(RegisterSupplyCommand cmd)
        {
            var supplyIsExist = _repositorySupply.GetSupplyCNPJ(cmd.CNPJ);

            if (supplyIsExist != null)
            {
                return(new ObjectRequest().CreateObjectRequest($" O CNPJ: {cmd.CNPJ} ja esta Cadastrado no Sistema ", false));
            }
            Address address   = new Address(cmd.Street, cmd.Number, cmd.Complement, cmd.District, cmd.City, cmd.State, cmd.CEP, null);
            Supply  newSupply = new Supply(cmd.CompanyName, cmd.CNPJ, cmd.Phone, cmd.Agent, cmd.Email, address);


            _repositoryAddress.AddEntity(address);
            _repositorySupply.AddEntity(newSupply);

            address.ListErrors().ForEach((X) => newSupply.ListErrors().Add(X));

            if (Commit(newSupply))
            {
                return(new ObjectRequest().CreateObjectRequest("Fornecedor Registrado com Sucesso", true));
            }

            return(new ObjectRequest().CreateErrorNotification(newSupply.ListErrors()));
        }