Example #1
0
        public async Task <EmprestimoResponse> EmprestarAsync(EmprestimoRequest emprestimoRequest)
        {
            var emprestimo = _mapper.Map <Emprestimo>(emprestimoRequest);


            emprestimo.DataEmprestimo        = DateTime.Now;
            emprestimo.DataPrevistaDeVolucao = CalcularDataPrevistaDevolucao(emprestimo);

            foreach (var item in emprestimo.ItensEmprestados)
            {
                item.Emprestimo = emprestimo;
            }

            return(await Task.FromResult(_mapper.Map <EmprestimoResponse>(_emprestimoRepositorio.Inserir(emprestimo))));
        }
        public async Task <EmprestimoResponse> Inserir(EmprestimoRequest request)
        {
            var amigo = await _context.Amigo.Include(x => x.Emprestimos).ThenInclude(y => y.Jogo)
                        .FirstOrDefaultAsync(x => x.Id == request.AmigoId);

            if (amigo == null)
            {
                _notification.AddNotification("Amigo", "Amigo não foi encontrado");
                return(null);
            }

            var jogo = await _context.Jogo.FirstOrDefaultAsync(x => x.Id == request.JogoId);

            if (jogo == null)
            {
                _notification.AddNotification("Jogo", "Jogo não foi encontrado");
                return(null);
            }

            if (jogo.Situacao == SituacaoJogo.Indisponivel)
            {
                _notification.AddNotification("Jogo", "Já existe um emprestimo para esse jogo");
                return(null);
            }

            var emprestimo = new Emprestimo(amigo, jogo);

            amigo.AddEmprestimo(emprestimo);

            _entityValidator.Validate(new Entity[] { emprestimo, amigo });

            if (_notification.HasNotifications)
            {
                return(null);
            }

            await _context.SaveChangesAsync();

            return(_mapper.Map <EmprestimoResponse>(emprestimo));
        }
Example #3
0
        public async Task <ActionResult <EmprestimoResponse> > Emprestar([FromBody] EmprestimoRequest emprestimo)
        {
            var EmprestimoResponse = await _emprestimoServico.EmprestarAsync(emprestimo).ConfigureAwait(false);

            return(Ok(EmprestimoResponse));
        }
 public Task <EmprestimoResponse> Atualizar(long id, EmprestimoRequest request)
 {
     throw new NotImplementedException();
 }