コード例 #1
0
        public EmprestimoViewModel CriarEmprestimo(EmprestimoInputModel emprestimoInputModel)
        {
            var carrinho = this._uow.CarrinhoRepository.GetCarrinhoPorSessionId(emprestimoInputModel.SessionUserID).ToList();

            var emprestimo = new Emprestimo()
            {
                DataInicio    = DateTime.Now.ToString(),
                DataFim       = DateTime.Now.AddDays(7).ToString(),
                DataDevolucao = null,
                UsuarioID     = GetUsuario()
            };

            foreach (var c in carrinho)
            {
                emprestimo.LivEmprestimo.Add(new LivroEmprestimo()
                {
                    LivroID = c.LivroID
                });
            }

            _uow.EmprestimoRepository.Add(emprestimo);
            _uow.Commit();

            foreach (var c in carrinho)
            {
                c.EmprestimoID = emprestimo.EmprestimoID;
                _uow.CarrinhoRepository.Update(c);
                _uow.Commit();
            }

            return(_mapper.Map <EmprestimoViewModel>(emprestimo));
        }
コード例 #2
0
        public ActionResult Post([FromBody] EmprestimoInputModel emprestimo)
        {
            var result = _emprestimoService.CriarEmprestimo(emprestimo);

            return(new CreatedAtRouteResult("GetEmprestimoDetails",
                                            new { id = result.Id }, result));
        }
コード例 #3
0
        public ActionResult DevolverLivros(int id, [FromBody] EmprestimoInputModel emprestimo)
        {
            if (id != emprestimo.Id)
            {
                return(BadRequest());
            }

            var result = _emprestimoService.DevolverLivros(emprestimo.Id);

            return(new CreatedAtRouteResult("GetEmprestimoDetails",
                                            new { id = result.Id }, result));
        }
コード例 #4
0
        public async Task <IActionResult> EmprestarLivros()
        {
            var url        = $"/Emprestimos";
            var emprestimo = new EmprestimoInputModel()
            {
                SessionUserId = GetCarrinhoKey()
            };

            var resposta = await _httpClient.PostAsJsonAsync(url, emprestimo);

            if (!resposta.IsSuccessStatusCode)
            {
                return(BadRequest());
            }

            TempData.Remove("CarrinhoKey");

            return(RedirectToAction("Index", "Emprestimos"));
        }
コード例 #5
0
        public async Task <IActionResult> DevolverLivros(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var emprestimo = new EmprestimoInputModel()
            {
                Id = id.Value
            };

            var url    = $"/Emprestimos/DevolverLivros/{id}";
            var result = await _httpClient.PostAsJsonAsync(url, emprestimo);

            if (!result.IsSuccessStatusCode)
            {
                return(BadRequest());
            }

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