예제 #1
0
        public HttpResponseMessage ManterEmprestimo(EmprestimoViewModel model)
        {
            try
            {
                if (model != null)
                {
                    var emprestimo = Mapper.Map <EmprestimoViewModel, Emprestimo>(model);
                    emprestimo.JogoId     = model.JogoId;
                    emprestimo.AmigoId    = model.AmigoId;
                    emprestimo.Observacao = model.Observacao;

                    if (emprestimo.EmprestimoId > 0)
                    {
                        var emp = _emprestimoService.RecuperarPorId(emprestimo.EmprestimoId);
                        emp.Observacao = model.Observacao;

                        _emprestimoService.Atualizar(emp);
                    }
                    else
                    {
                        AdicionarNovoEmprestimo(emprestimo);
                    }

                    AtualizarSituacaoEmprestimoJogo(emprestimo.JogoId, true);
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
                return(response);
            }
            catch (Exception ex)
            {
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
                return(response);
            }
        }
예제 #2
0
        public ActionResult Devolver(long EmprestimoId)
        {
            var emprestimo = _emprestimoAppService.Obter <EmprestimoViewModel>(var => var.IdUsuario == CookieManager.UsuarioId &&
                                                                               var.IdEmprestimo == EmprestimoId);

            if (emprestimo == null)
            {
                return(Json(new { sucesso = false, mensagem = "Não encontramos emprestimo." }));
            }

            emprestimo.IdStatusEmprestimo = 2;
            emprestimo.DataDevolucao      = DateTime.Now;

            var atualizado = _emprestimoAppService.Atualizar(emprestimo);

            if (atualizado == null)
            {
                return(Json(new { sucesso = false, mensagem = "Erro ao devolver jogo. Verifique as informações e tente novamente." }));
            }
            else
            {
                return(Json(new { sucesso = true, mensagem = "Jogo devolvido com sucesso" }));
            }
        }