コード例 #1
0
 public void Inserir(OrcamentoServico objeto)
 {
     //string query = "INSERT INTO ORCAMENTO_PUBLICIDADE_SERVICO (EmpresaID, OrcamentoID, ServicoPrestadoID, Quantidade, ValorTotal) VALUES ({0}, {1}, {2}, {3}, {4})";
     //_contexto.Database.ExecuteSqlCommand(query, objeto.EmpresaID, objeto.OrcamentoID, objeto.ServicoPrestadoID, objeto.Quantidade, objeto.ValorTotal);
     _contexto.OrcamentoServicos.Add(objeto);
     Salvar();
 }
コード例 #2
0
 public OrcamentoController()
 {
     _servico            = new OrcamentoServico();
     _moduloServico      = new ModuloServico();
     _produtoServico     = new ProdutoServico();
     _orcamentoViewModel = new OrcamentoViewModel();
 }
コード例 #3
0
        public void ValidarCampos(OrcamentoServico oss)
        {
            try
            {
                if (oss == null)
                {
                    throw new ArgumentException("Serviços do Orçamento inválidos");
                }

                if (oss.EmpresaID.Equals(null))
                {
                    throw new ArgumentException("Erro ao obter Empresa. Orçamento - Serviços");
                }

                if (!oss.Quantidade.Equals(null) && oss.Quantidade <= 0)
                {
                    throw new ArgumentException("O campo Quantidade deve ser maior que 0");
                }

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

                if (!oss.ServicoPrestadoID.Equals(null) && oss.ServicoPrestadoID <= 0)
                {
                    throw new ArgumentException("Serviço Pestado inválido");
                }

                if (!oss.ValorTotal.Equals(null) && oss.ValorTotal <= 0)
                {
                    throw new ArgumentException("Valor Total Serviços inválido");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #4
0
 public void Atualizar(OrcamentoServico objeto)
 {
     _contexto.OrcamentoServicos.Update(objeto);
     Salvar();
 }
コード例 #5
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));
            }
        }
コード例 #6
0
        public ActionResult Novo(OrcamentoEditarViewModel model)
        {
            var clienteServico = new ClienteServico();
            var usuarioServico = new UsuarioServico();
            var cidadeServico  = new CidadeServico();

            model.Orcamento.Data         = model.DataEmissao;
            model.Orcamento.DataSituacao = model.DataSituacao;

            var clienteModel = clienteServico.ObterPorId(model.Orcamento.ClienteId.Value);

            if (clienteModel != null)
            {
                foreach (var itemEmail in clienteModel.Emails)
                {
                    var modelEmail = new OrcamentoEmail();
                    modelEmail.Email     = itemEmail.Email;
                    modelEmail.Orcamento = model.Orcamento;
                    model.Orcamento.OrcamentoEmails.Add(modelEmail);
                }

                foreach (var itemContato in clienteModel.Contatos)
                {
                    var modelContato = new Contato();
                    modelContato.Email     = itemContato.Email;
                    modelContato.Fone1     = itemContato.Fone1;
                    modelContato.Fone2     = itemContato.Fone2;
                    modelContato.Nome      = itemContato.Nome;
                    modelContato.Orcamento = model.Orcamento;
                    model.Orcamento.Contatos.Add(modelContato);
                }
            }

            model.Orcamento.Enquadramento = clienteModel.Enquadramento;
            model.Orcamento.RazaoSocial   = clienteModel.Nome;
            model.Orcamento.SubTipo       = 2;

            _servico.Salvar(model.Orcamento);

            var servico2 = new OrcamentoServico();

            model.Orcamento = servico2.ObterPorId(model.Orcamento.Id);

            model.DataEmissao  = model.Orcamento.Data;
            model.DataSituacao = model.Orcamento.DataSituacao;
            model.ListaTipos   = ListarTipo();

            model.NomeUsuario = model.Orcamento.Usuario.Nome;

            if (model.Orcamento.Cliente != null)
            {
                model.NomeCliente = model.Orcamento.Cliente.Nome;
            }

            if (model.Orcamento.Cidade != null)
            {
                model.NomeCidade = model.Orcamento.Cidade.Nome;
                model.UF         = model.Orcamento.Cidade.UF;
            }

            return(View(model));
        }