public IActionResult Put([FromBody] AluguelModel aluguel) { try { Aluguel aluguelRequisicaoPut = _mapper.Map <AluguelModel, Aluguel>(aluguel); if (aluguelRequisicaoPut.Invalid) { return(StatusCode(StatusCodes.Status400BadRequest, new ErrorModel(aluguelRequisicaoPut.Notifications))); } var aluguelExistente = _aluguelRepositorio.Obter(aluguelRequisicaoPut.IdAluguel); if (aluguelExistente != null) { _aluguelRepositorio.Atualizar(aluguelRequisicaoPut); } else { return(StatusCode(StatusCodes.Status404NotFound, Constantes.Mensagens.AluguelNaoEncontrado)); } return(Ok()); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, Constantes.Mensagens.ServicoIndisponivel)); throw; } }
public void CadastrarAluguel(AluguelModel aluguel) { SqlCommand command = new() { Connection = connection }; #region Parâmetros command.Parameters.AddWithValue("@titulo", aluguel.titulo); command.Parameters.AddWithValue("@autor", aluguel.autor); command.Parameters.AddWithValue("@alugadoPor", aluguel.alugadoPor); command.Parameters.AddWithValue("@dataSaida", aluguel.dataEntrega); command.Parameters.AddWithValue("@dataDevolucao", aluguel.dataDevolucao); command.Parameters.AddWithValue("@status", aluguel.status); #endregion try { command.CommandText = "INSERT INTO Aluguel(Titulo, Autor, [Alugado por], [Data de saida], [Data de devolucao], Status) " + "VALUES(@titulo, @autor, @alugadoPor, @dataSaida, @dataDevolucao, @status)"; AbrirConexaoDb(); command.ExecuteNonQuery(); FechaConecxaoDb(); command.Dispose(); MessageBox.Show(Resources.AluguelRegistrado, Resources.concluido_MessageBox, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (SqlException e) { MessageBox.Show(e.Message, Resources.MessageBoxError, MessageBoxButtons.OK, MessageBoxIcon.Error); AppInsightMetrics.SendError(e); } }
public IActionResult SimularAluguel([FromBody] AluguelModel aluguel) { try { Aluguel aluguelRequisicaoPost = _mapper.Map <AluguelModel, Aluguel>(aluguel); if (aluguelRequisicaoPost.Invalid) { return(StatusCode(StatusCodes.Status400BadRequest, new ErrorModel(aluguelRequisicaoPost.Notifications))); } var retornoSimulacao = _aluguelService.Simular(aluguelRequisicaoPost); if (retornoSimulacao.Invalid) { return(StatusCode(StatusCodes.Status400BadRequest, new ErrorModel(retornoSimulacao.Notifications))); } else { return(Ok(_mapper.Map <Aluguel, AluguelModel>(retornoSimulacao))); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Constantes.Mensagens.ServicoIndisponivel)); throw; } }
public static MemoryStream GerarContratoAluguel(AluguelModel aluguel) { Document document = new Document(); MemoryStream stream = new MemoryStream(); try { PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream); pdfWriter.CloseStream = false; document.Open(); document.Add(new Paragraph("Este é o modelo de contrato de locação de veículo default.")); document.Add(new Paragraph("Locador: ________________________")); document.Add(new Paragraph("Locatario: ________________________")); document.Add(new Paragraph("Placa: ________________________")); document.Add(new Paragraph("Modelo gerado com o intuito de apresentar o funcionamento da geração e retorno do pdf através da API.")); document.Add(new Paragraph("Segue JSON com dados do Aluguel:")); document.Add(new Paragraph(System.Text.Json.JsonSerializer.Serialize(aluguel).ToString())); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } document.Close(); stream.Flush(); stream.Position = 0; return(stream); }
public void AtualizarAluguelNomeCliente(AluguelModel aluguel, string nomeCliente, string nomeLivro) { SqlCommand command = new() { Connection = connection }; #region Parâmetros command.Parameters.AddWithValue("@titulo", aluguel.titulo); command.Parameters.AddWithValue("@autor", aluguel.autor); command.Parameters.AddWithValue("@alugadoPor", aluguel.alugadoPor); command.Parameters.AddWithValue("@dataSaida", aluguel.dataEntrega); command.Parameters.AddWithValue("@dataDevolucao", aluguel.dataDevolucao); command.Parameters.AddWithValue("@status", aluguel.status); #endregion try { command.CommandText = "UPDATE Aluguel SET Titulo = @titulo, Autor = @autor, [Alugado por] = @alugadoPor," + $" [Data de saida] = @dataSaida, [Data de devolucao] = @dataDevolucao, Status = @status WHERE [Alugado por] = \'{nomeCliente}\' " + $"AND Titulo = \'{nomeLivro}\'"; AbrirConexaoDb(); command.ExecuteNonQuery(); FechaConecxaoDb(); command.Dispose(); MessageBox.Show(Resources.informações_atualizadas, Resources.concluido_MessageBox, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (SqlException e) { MessageBox.Show(e.Message, Resources.MessageBoxError, MessageBoxButtons.OK, MessageBoxIcon.Error); AppInsightMetrics.SendError(e); } }
public ActionResult Delete(int id) { Aluguel aluguel = _aluguelService.Buscar(id); AluguelModel aluguelModel = _mapper.Map <AluguelModel>(aluguel); return(View(aluguelModel)); }
public ActionResult Edit(int id, AluguelModel aluguelModel) { if (ModelState.IsValid) { var aluguel = _mapper.Map <Aluguel>(aluguelModel); _aluguelService.Alterar(aluguel); } return(RedirectToAction(nameof(Index))); }
public ActionResult Create(AluguelModel aluguelModel) { if (ModelState.IsValid) { var aluguel = _mapper.Map <Aluguel>(aluguelModel); _aluguelService.Inserir(aluguel); } return(RedirectToAction(nameof(Index))); }
protected void SalvarReservaCookie(AluguelModel aluguel) { if (aluguel != null) { CookieOptions cookieOptions = new CookieOptions(); cookieOptions.Expires = DateTime.Now.AddMinutes(10); string value = JsonSerializer.Serialize <AluguelModel>(aluguel); Response.Cookies.Append(_chaveCookieReserva, value, cookieOptions); } }
public ActionResult Edit(int id) { Aluguel aluguel = _aluguelService.Buscar(id); AluguelModel aluguelModel = _mapper.Map <AluguelModel>(aluguel); IEnumerable <Statuspagamento> listarStatusPagamento = _statusPagamentoService.ObterTodos(); ViewBag.IdStatusPagamento = new SelectList(listarStatusPagamento, "CodigoStatusPagamento", "Descricao", null); return(View(aluguelModel)); }
public IActionResult ConcluirReserva(AluguelModel aluguel) { var aluguelcookie = RecuperarReservaCookie(); var aluguelParaProcessamento = aluguelcookie != null && !aluguelcookie.IdVeiculo.Equals(0) ? aluguelcookie : aluguel; if (!VerificarUsuarioLogado()) { SalvarReservaCookie(aluguelParaProcessamento); return(RedirectToAction("Login", "CadastroUsuario", new UsuarioModel() { PreReserva = true })); } var clienteLogado = ObterClienteLogado(); if (clienteLogado?.IdCliente == 0 && aluguel.IdCliente.Equals(0)) { SalvarReservaCookie(aluguelParaProcessamento); return(RedirectToAction("Index", "CadastroCliente", new ClienteModel() { PreReserva = true })); } aluguelParaProcessamento.IdCliente = clienteLogado.IdCliente; if (aluguelParaProcessamento != null) { AluguelDTO aluguelDTO = new AluguelDTO() { Veiculo = new VeiculoDTO() { IdVeiculo = aluguelParaProcessamento.IdVeiculo, Placa = aluguelParaProcessamento.Placa }, Cliente = new ClienteDTO() { IdCliente = aluguelParaProcessamento.IdCliente }, TotalDeHoras = aluguelParaProcessamento.TotalDeHoras, DataPrevistaAluguel = aluguelParaProcessamento.DataPrevistaAluguel, ValorHora = aluguelParaProcessamento.ValorHora, ValorFinal = aluguelParaProcessamento.ValorFinalAluguel }; _reservaBLL.EfetuarAluguel(aluguelDTO, ObterJWToken()); RemoverReservaCookie(); } else { return(View("Index", "Home")); } base.PreencherViewBagUsuarioLogado(); return(View("ReservaConcluida")); }
public void DetailsTest() { // Act var result = controller.Details(1); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); ViewResult viewResult = (ViewResult)result; Assert.IsInstanceOfType(viewResult.ViewData.Model, typeof(AluguelModel)); AluguelModel aluguelModel = (AluguelModel)viewResult.ViewData.Model; Assert.AreEqual("Aluguel da Maria", aluguelModel.Descricao); Assert.AreEqual(1, aluguelModel.CodigoStatusPagamento); }
public IActionResult Get(int id) { try { AluguelModel currentModel = AluguelModel.ToModel(_aluguelBusiness.Get(id)); if (currentModel == null) { return(NotFound()); } return(Ok(currentModel.ToBody())); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public IActionResult GetClientesInadimplentes() { try { IEnumerable <AluguelModel> currentModel = AluguelModel.ToListModel(_aluguelBusiness.Get(p => DateTime.Now > p.Devolucao)); if (currentModel == null) { return(NotFound()); } return(Ok(ListBodyModel <AluguelModel> .ToBodyList(currentModel))); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public IActionResult GetAlugueisAtivos() { try { IEnumerable <AluguelModel> currentModel = AluguelModel.ToListModel(_aluguelBusiness.Get(p => p.Devolveu == null)); if (currentModel == null) { return(NotFound()); } return(Ok(ListBodyModel <AluguelModel> .ToBodyList(currentModel))); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public IActionResult GetByCliente(int clienteId) { try { IEnumerable <AluguelModel> currentModel = AluguelModel.ToListModel(_aluguelBusiness.Get( p => p.ClienteId == clienteId && (p.Devolveu == null || p.Devolveu == DateTime.MinValue))); if (currentModel == null) { return(NotFound()); } return(Ok(ListBodyModel <AluguelModel> .ToBodyList(currentModel))); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public IActionResult Put(int id, AluguelModel editedModel) { try { Aluguel currentModel = _aluguelBusiness.Get(id); if (currentModel == null) { return(NotFound()); } _aluguelBusiness.Edit(currentModel, editedModel.ToDomain()); return(Ok(editedModel.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)); } }
public IActionResult Delete(int id) { try { AluguelModel currentModel = AluguelModel.ToModel(_aluguelBusiness.Get(id)); if (currentModel == null) { return(NotFound()); } if (currentModel.IsValidToDesactive()) { _aluguelBusiness.Desactive(currentModel.ToDomain()); return(Ok(currentModel.ToBody())); } return(BadRequest("Não foi possível desativar este aluguel, pois já possui valor pago ou multa.")); } catch (Exception ex) { throw ex; } }
public AluguelController() { aluguelModel = new AluguelModel(); }
public ActionResult Delete(int id, AluguelModel aluguelModel) { _aluguelService.Excluir(id); return(RedirectToAction(nameof(Index))); }
/// <summary> /// Verificar todos os campos obrigatórios em <c>Aluguel</c>. /// </summary> /// <param name="aluguel"><c>Aluguel</c> que será analisado</param>. /// <returns>Retorna <c>error</c></returns> public static bool VerificarCamposAluguel(AluguelModel aluguel) { return(aluguel.titulo.Length == 0 || aluguel.autor.Length == 0 || aluguel.alugadoPor.Length == 0); }