Ejemplo n.º 1
0
        public IActionResult Get(int id)
        {
            try
            {
                ClienteModel currentModel = ClienteModel.ToModel(_clienteBusiness.Get(id));

                if (currentModel == null)
                {
                    return(NotFound());
                }

                return(Ok(currentModel.ToBody()));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Ejemplo n.º 2
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));
            }
        }