Пример #1
0
        public IActionResult Gravar(LocacaoViewModel viewModel)
        {
            ActionResult action = ValidarLogin(HttpContext);

            if (action != null)
            {
                return(action);
            }

            var repo              = new Repo();
            var tipoProduto       = repo.SelecionarProdutoTipoPorId(repo.SelecionarProdutoPorId(viewModel.IdProduto).IdProdutoTipo);
            var dtLimiteDevolucao = !string.IsNullOrEmpty(viewModel.DtLimiteDevolucao) ? Convert.ToDateTime(viewModel.DtLimiteDevolucao) : DateTime.Now.AddDays(tipoProduto.Prazo);

            Locacao locacao = new Locacao()
            {
                IdUsuario         = Sessao.GetIdUsuario(HttpContext),
                IdProduto         = viewModel.IdProduto,
                IdCliente         = viewModel.IdCliente,
                IdLocacao         = viewModel.IdLocacao,
                DtDevolucao       = string.IsNullOrEmpty(viewModel.DtDevolucao) ? null : (DateTime?)(Convert.ToDateTime(viewModel.DtDevolucao)),
                DtLimiteDevolucao = dtLimiteDevolucao,
                DtLocacao         = DateTime.Now
            };

            var retorno = repo.GravarLocacao(locacao);

            if (retorno == string.Empty)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(Json(new { Result = false, Message = retorno }));
            }
        }
Пример #2
0
        public IActionResult Index()
        {
            ActionResult action = ValidarLogin(HttpContext);

            if (action != null)
            {
                return(action);
            }

            var viewModel   = new List <LocacaoExibicaoViewModel>();
            var repositorio = new Repo();

            var locacoes = repositorio.SelecionarLocacoes();

            foreach (var locacao in locacoes)
            {
                var atrasado = false;
                if (locacao.DtDevolucao.HasValue && locacao.DtDevolucao.Value != new DateTime())
                {
                    atrasado = locacao.DtDevolucao.Value > locacao.DtLimiteDevolucao;
                }
                else
                {
                    atrasado = DateTime.Now > locacao.DtLimiteDevolucao;
                }

                LocacaoExibicaoViewModel item = new LocacaoExibicaoViewModel
                {
                    IdLocacao         = locacao.IdLocacao.Value,
                    DtLocacao         = locacao.DtLocacao.ToString("dd/MM/yyyy HH:mm:ss"),
                    DtDevolucao       = ((!locacao.DtDevolucao.HasValue) || (locacao.DtDevolucao.Value == new DateTime())) ? "" : locacao.DtDevolucao.Value.ToString("dd/MM/yyyy"),
                    DtLimiteDevolucao = locacao.DtLimiteDevolucao.ToString("dd/MM/yyyy"),
                    Cliente           = repositorio.SelecionarNomeCliente(locacao.IdCliente),
                    Usuario           = repositorio.SelecionarNomeUsuario(locacao.IdUsuario),
                    Produto           = repositorio.SelecionarNomeProduto(locacao.IdProduto),
                    Atrasado          = atrasado
                };
                viewModel.Add(item);
            }

            return(View(viewModel));
        }
Пример #3
0
        public IActionResult Devolver(int id)
        {
            ActionResult action = ValidarLogin(HttpContext);

            if (action != null)
            {
                return(action);
            }

            var repo = new Repo();

            Locacao locacao = repo.SelecionarLocacaoPorId(id);
            var     retorno = repo.DevolverLocacao(locacao);

            if (retorno == string.Empty)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(Json(new { Result = false, Message = retorno }));
            }
        }
Пример #4
0
        public IActionResult Editar(int id)
        {
            ActionResult action = ValidarLogin(HttpContext);

            if (action != null)
            {
                return(action);
            }

            Repo repositorio = new Repo();

            LocacaoViewModel viewModel = new LocacaoViewModel();
            Locacao          locacao   = repositorio.SelecionarLocacaoPorId(id);

            viewModel.IdCliente         = locacao.IdCliente;
            viewModel.IdLocacao         = locacao.IdLocacao;
            viewModel.IdProduto         = locacao.IdProduto;
            viewModel.DtDevolucao       = (locacao.DtDevolucao.HasValue && (locacao.DtDevolucao.Value != new DateTime()))? locacao.DtDevolucao.Value.ToString("yyyy-MM-dd") : "";
            viewModel.DtLimiteDevolucao = locacao.DtLimiteDevolucao.ToString("yyyy-MM-dd");

            ViewBag.Adicionar = false;

            return(View("NovaLocacao", viewModel));
        }