public IActionResult Get(int id) { try { FilmeModel currentModel = FilmeModel.ToModel(_filmeBusiness.Get(id)); if (currentModel == null) { return(NotFound()); } return(Ok(currentModel.ToBody())); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
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)); } }