コード例 #1
0
        public IActionResult Post(AluguelModel newModel)
        {
            try
            {
                if (newModel != null && newModel.IsValid())
                {
                    Aluguel aluguel = newModel.ToDomain();
                    aluguel.Cliente     = _clienteBusiness.Get(newModel.ClienteId);
                    aluguel.Funcionario = _funcionarioBusiness.Get(newModel.FuncionarioId);
                    aluguel.Filme       = _filmeBusiness.Get(newModel.FilmeId);
                    aluguel.Devolucao   = DateTime.Now.AddDays(_aluguelBusiness.DiasParaDevolucao());
                    aluguel.Cadastro    = DateTime.Now;
                    aluguel.Ativo       = true;
                    _aluguelBusiness.Add(aluguel);
                    return(Ok(newModel.ToBody()));
                }

                return(BadRequest("Preencha corretamente todos os campos do aluguel."));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }