public void ValidarCampos(OrcamentoFornecedor fornecedor)
        {
            try
            {
                if (fornecedor == null)
                {
                    throw new ArgumentException("Fornecedor inválido");
                }

                if (fornecedor.EmpresaID.Equals(null))
                {
                    throw new ArgumentException("Erro ao obter Empresa.");
                }

                if (fornecedor.OrcamentoID.Equals(null))
                {
                    throw new ArgumentException("Orçamento inválido");
                }

                if (!fornecedor.OrcamentoID.Equals(null) && fornecedor.OrcamentoID <= 0)
                {
                    throw new ArgumentException("Orçamento inválido");
                }

                if (String.IsNullOrEmpty(fornecedor.Descricao))
                {
                    throw new ArgumentException("Campo Descrição (Fornecedor) é obrigatório");
                }

                if (fornecedor.FornecedorID.Equals(null))
                {
                    throw new ArgumentException("Fornecedor inválido");
                }

                if (!fornecedor.FornecedorID.Equals(null) && fornecedor.FornecedorID <= 0)
                {
                    throw new ArgumentException("Fornecedor inválido");
                }

                if (fornecedor.Quantidade.Equals(null))
                {
                    throw new ArgumentException("Campo Quantidade (Fornecedor) inválido");
                }

                if (fornecedor.Quantidade <= 0)
                {
                    throw new ArgumentException("O campo Quantidade (Fornecedor) deve ser maior que zero.");
                }

                if (!fornecedor.ValorUnitario.Equals(null) && fornecedor.ValorUnitario <= 0)
                {
                    throw new ArgumentException("Campo Valor Unitário (Fornecedor) é obrigatório");
                }

                if (!fornecedor.ValorTotal.Equals(null) && fornecedor.ValorTotal <= 0)
                {
                    throw new ArgumentException("Campo Valor Total (Fornecedor) é obrigatório");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
 public void Inserir(OrcamentoFornecedor objeto)
 {
     _contexto.OrcamentoFornecedores.Add(objeto);
     Salvar();
 }
Esempio n. 3
0
        public ActionResult Create(Orcamento orcamento)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    orcamento.EmpresaID = Convert.ToInt32(User.FindFirst(ClaimTypes.GroupSid).Value);

                    OrcamentoService service = new OrcamentoService();
                    service.PreencherCampos(orcamento);

                    _orcamento.Inserir(orcamento);

                    //Tratar o JSON da lista de serviços e transformar no objeto OrcamentoPublicidadeServicos
                    if (!String.IsNullOrEmpty(orcamento.ServicosJSON))
                    {
                        List <OrcamentoServico> ListaServicos = JsonConvert.DeserializeObject <List <OrcamentoServico> >(orcamento.ServicosJSON);
                        if (ListaServicos.Count >= 1)
                        {
                            for (int i = 0; i < ListaServicos.Count; i++)
                            {
                                var os = new OrcamentoServico();
                                os.EmpresaID         = orcamento.EmpresaID;
                                os.OrcamentoID       = orcamento.OrcamentoID;
                                os.ServicoPrestadoID = ListaServicos[i].ServicoPrestadoID;
                                os.Quantidade        = ListaServicos[i].Quantidade;
                                os.ValorTotal        = ListaServicos[i].ValorTotal;

                                OrcamentoServicoService oss = new OrcamentoServicoService();
                                oss.ValidarCampos(os);

                                _orcamentoServico.Inserir(os);
                            }
                        }
                    }


                    //Tratar o JSON da lista de Fornecedores e transformar no objeto OrcamentoFornecedores
                    if (!String.IsNullOrEmpty(orcamento.FornecedoresJSON))
                    {
                        List <OrcamentoFornecedor> ListaFornecedores = JsonConvert.DeserializeObject <List <OrcamentoFornecedor> >(orcamento.FornecedoresJSON);
                        if (ListaFornecedores.Count >= 1)
                        {
                            for (int i = 0; i < ListaFornecedores.Count; i++)
                            {
                                var of = new OrcamentoFornecedor();
                                of.EmpresaID     = orcamento.EmpresaID;
                                of.OrcamentoID   = orcamento.OrcamentoID;
                                of.FornecedorID  = ListaFornecedores[i].FornecedorID;
                                of.Descricao     = ListaFornecedores[i].Descricao;
                                of.Quantidade    = ListaFornecedores[i].Quantidade;
                                of.ValorUnitario = ListaFornecedores[i].ValorUnitario;
                                of.ValorTotal    = ListaFornecedores[i].ValorTotal;

                                OrcamentoFornecedorService opfs = new OrcamentoFornecedorService();
                                opfs.ValidarCampos(of);

                                _orcamentoFornecedor.Inserir(of);
                            }
                        }
                    }


                    //Tratar o JSON da lista de Custos de Produção e transformar no objeto OrcamentoCustos
                    if (!String.IsNullOrEmpty(orcamento.CustoProducaoJSON))
                    {
                        List <OrcamentoCustos> ListaCustos = JsonConvert.DeserializeObject <List <OrcamentoCustos> >(orcamento.CustoProducaoJSON);
                        if (ListaCustos.Count >= 1)
                        {
                            for (int i = 0; i < ListaCustos.Count; i++)
                            {
                                var oc = new OrcamentoCustos();
                                oc.EmpresaID     = orcamento.EmpresaID;
                                oc.OrcamentoID   = orcamento.OrcamentoID;
                                oc.Descricao     = ListaCustos[i].Descricao;
                                oc.Quantidade    = ListaCustos[i].Quantidade;
                                oc.ValorUnitario = ListaCustos[i].ValorUnitario;
                                oc.UnidadeValor  = ListaCustos[i].UnidadeValor;
                                oc.ValorTotal    = ListaCustos[i].ValorTotal;

                                OrcamentoCustosService opcs = new OrcamentoCustosService();
                                opcs.ValidarCampos(oc);

                                _orcamentoCusto.Inserir(oc);
                            }
                        }
                    }

                    return(RedirectToAction(nameof(Index)));
                }

                CarregarCampos();
                return(View(orcamento));
            }
            catch (Exception ex)
            {
                Mensagem = ex.Message.ToString();
                ModelState.AddModelError(String.Empty, Mensagem);
                return(View(orcamento));
            }
        }
Esempio n. 4
0
 public void Atualizar(OrcamentoFornecedor objeto)
 {
     throw new NotImplementedException();
 }