Пример #1
0
        public async Task <EmprestimoViewModel> Criar(EmprestimoViewModel emprestimo)
        {
            var validacao = await _emprestimoValidacaoInclusao.Validar(emprestimo);

            if (validacao.IsValid)
            {
                emprestimo.DataEmprestimo    = DateTime.Now;
                emprestimo.DataPrevDevolucao = DateTime.Now.AddMonths(1);
                emprestimo.Status            = (int)EStatusEmprestimo.PENDENTE;


                var obj = await _emprestimoRepositorio.Criar(_mapper.Map <Emprestimo>(emprestimo));

                _ = await _livroServico.Emprestar(emprestimo.LivroId);

                return(_mapper.Map <EmprestimoViewModel>(obj));
            }

            Erros.AddRange(validacao.Errors.Select(erro => erro.ErrorMessage).ToList());
            return(emprestimo);
        }