示例#1
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()));
        }