예제 #1
0
 private int GetIdAgendamento(DebitoDiretoModel debito)
 {
     var agendamento = new Agendamento
     {
         AlteradoEm = DateTime.Now,
         AlteradoPor = debito.AlteradoPor,
         CadastradoEm = DateTime.Now,
         CadastradoPor = debito.AlteradoPor,
         Ativo = true,
         Descricao = string.IsNullOrEmpty(debito.Descricao) ? string.Empty : debito.Descricao.ToUpper().Trim(),
         IdEmpresa = debito.IdEmpresa,
         IdFornecedor = debito.IdFornecedor,
         IdGrupoCusto = debito.IdGrupoCusto,
         IdItemCusto = debito.IdItemCusto,
         Observ = string.Empty,
         Referencia = debito.Referencia
     };
     return _agendamento.Gravar(agendamento);
 }
        public ActionResult Index(Agendamento agendamento, FormCollection collection)
        {
            try
            {
                agendamento.Observ = string.Empty;
                agendamento.Ativo = true;
                agendamento.AlteradoEm = DateTime.Now;
                agendamento.AlteradoPor = Identification.IdUsuario;

                if (agendamento.Id == 0)
                {
                    agendamento.CadastradoEm = DateTime.Now;
                    agendamento.CadastradoPor = Identification.IdUsuario;
                }

                if (ModelState.IsValid)
                {
                    if (agendamento.Id == 0)
                    {
                        return RedirectToAction("Incluir", "Parcela", new { idAgendamento = _service.Gravar(agendamento) });
                    }
                    else
                    {
                        // TODO: TEM QUE TER INTERACAO COM O USUARIO NA TELA INDEX
                        return RedirectToAction("Index", new { id = _service.Gravar(agendamento) });
                    }
                }

                return View(agendamento);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return View(agendamento);
            }
        }
        // GET: Controle/Agendamento
        public ActionResult Index(int id = 0, int idEmpresa = 0, int idGrupoCusto = 0, int idItemCusto = 0, int idFornecedor = 0, DateTime? referencia = null)
        {
            Agendamento agendamento = new Agendamento();

            if (id > 0)
            {
                agendamento = _service.Find(id);
                if (agendamento == null)
                {
                    id = 0;
                }
            }

            if (id == 0)
            {
                agendamento = new Agendamento { IdEmpresa = idEmpresa, IdGrupoCusto = idGrupoCusto, IdItemCusto = idItemCusto, IdFornecedor = idFornecedor };
                if (referencia == null)
                {
                    agendamento.Referencia = DateTime.Today.Date;
                }
                else
                {
                    agendamento.Referencia = (DateTime)referencia;
                }
            }

            return View(agendamento);
        }