private void SaveRentBtn_Click(object sender, System.EventArgs e) { if (!OnlyViewMode) { if (SaveRentBtn.Text.Equals("Procesar renta")) { //Process the rent RentDTO dto = FillRentDto(); dao.ProcessRent(dto); //Return to inspection container. SaveRentBtn.DialogResult = DialogResult.OK; } } else if (SaveRentBtn.Text.Equals("Devolver")) { RentDTO dto = FillRentDto(); dao.DevolutionProcess(dto); rentsDV.DataSource = dao.GetActiveRents(); } else { MessageBox.Show("Favor realizar una inspeccion primero. en este modo solo se pueden visualizar las rentas :D"); } }
public async Task <ActionResult <RentDTO> > PutRent(int id, RentDTO dto) { var rent = await _context.Rent.Include(x => x.RentEquipment).FirstOrDefaultAsync(x => x.Id == id); if (rent == null) { return(NotFound()); } if (HttpContext.IsAdmin()) { rent.ShopId = dto.ShopId; } rent.Customer = dto.Customer; rent.From = dto.From; rent.To = dto.To; rent.Closed = dto.Closed; rent.Payment = dto.Payment; rent.Comment = dto.Comment; rent.RentEquipment = dto.EquipmentIds.Select(x => new RentEquipment { EquipmentId = x }).ToList(); await _context.SaveChangesAsync(); return(dto); }
public ActionResult Create(RentDTO dto) { var rent = new Rent(); rent.Contact = dto.Contact; rent.Car = dto.Car; rent.Fare = dto.RentTime * 500; rent.RentTime = dto.RentTime; try { db.Rents.Add(rent); db.SaveChanges(); if (rent.Id != 0) { TempData["UserMessages"] = "You reqyuestn is forwar you will be contacted soon."; //Session["loginUser"] = user; return(RedirectToAction("Index", "home")); } else { TempData["error"] = "Rent a car request not confirmed. Try again" + "Error Message"; return(RedirectToAction("Create", "Rent")); } } catch { return(View()); } }
public async Task <ActionResult <RentDTO> > PostRent(RentDTO dto) { var shopId = HttpContext.IsAdmin() ? dto.ShopId : HttpContext.GetShopId(); var rent = new Rent { EmployeeId = HttpContext.GetEmployeeId(), Customer = dto.Customer, ShopId = shopId, From = dto.From, To = dto.To, Closed = null, Payment = dto.Payment, Comment = dto.Comment, RentEquipment = dto.EquipmentIds?.Select(x => new RentEquipment { EquipmentId = x }).ToList() }; _context.Rent.Add(rent); await _context.SaveChangesAsync(); dto.Id = rent.Id; return(CreatedAtAction("GetRent", new { id = rent.Id }, dto)); }
public Rent(RentDTO dto) { Id = dto.Id; ClientId = dto.ClientId; VehicleId = dto.VehicleId; StartDate = dto.StartDate; FinishDate = dto.FinishDate; Price = dto.Price; Finished = dto.Finished; }
private void FinalizeRent(RentDTO rent) { if (rent == null) { return; } SelectedRent = rent; OnRentFinalizeStarted(); }
public bool VolumeAlreadyRented(RentDTO rent) { var volRents = Rents.Where(r => r.VolumeId == rent.VolumeId && r.IsActive).ToList(); if (volRents.Count == 1 && volRents.First().Id != rent.Id) { return(true); } return(false); }
public async Task UpdateRentAsync(RentDTO rent) { try { HttpResponseMessage response = await _client.PutAsJsonAsync("api/rents/", rent); } catch (Exception ex) { throw new PersistenceUnavailableException(ex); } }
internal RentDTO ToDto() { var dto = new RentDTO(); dto.Id = Id; dto.ClientId = ClientId; dto.FinishDate = FinishDate; dto.Finished = Finished; dto.VehicleId = VehicleId; dto.Price = Price; dto.StartDate = StartDate; return(dto); }
// Véglegesítem a rendelést ( updatelem ) public async Task <bool> DoneRentAsync(RentDTO rent) { try { HttpResponseMessage response = await _client.PutAsJsonAsync("api/rent/", rent); return(response.IsSuccessStatusCode); } catch (Exception ex) { throw new PersistenceUnavailableException(ex); } }
//Rendelés módosítása public async Task UpdateRent(RentDTO rent) { if (rent == null) { throw new ArgumentNullException(nameof(rent)); } if (VolumeAlreadyRented(rent)) { throw new InvalidOperationException("Ez a kötet jelenleg ki van adva!"); } await _persistence.UpdateRentAsync(rent); }
private void FillRentParams(SqlCommand cmd, RentDTO dto) { cmd.Parameters.AddWithValue("@id", dto.Id); cmd.Parameters.AddWithValue("@employeeInfo", dto.EmployeeInfo); cmd.Parameters.AddWithValue("@inspectionId", dto.InspectionId); cmd.Parameters.AddWithValue("@carId", dto.CarId); cmd.Parameters.AddWithValue("@carInfo", dto.CarInfo); cmd.Parameters.AddWithValue("@customerInfo", dto.CustomerInfo); cmd.Parameters.AddWithValue("@rent_date", dto.RentDate); cmd.Parameters.AddWithValue("@devolution_date", dto.DevolutionDate); cmd.Parameters.AddWithValue("@mont_x_day", dto.MontPerDay); cmd.Parameters.AddWithValue("@quantity_of_days", dto.QuantityOfDays); cmd.Parameters.AddWithValue("@comment", dto.Comment); cmd.Parameters.AddWithValue("@status", 1); }
public IActionResult PutProduct([FromBody] RentDTO rentDTO) { try { Rent selectedRent = _context.Rents.FirstOrDefault(b => b.Id == rentDTO.Id); List <RentProductConnection> rentedProductsForSelectedRent = _context.RentProductConnections.Where(rp => rp.RentId == selectedRent.Id).ToList(); List <Product> products = _context.Products.ToList(); // Ha kell módosítjuk az raktárkészletet az egyes termékeknél if (selectedRent == null) // ha nincs ilyen azonosító, akkor hibajelzést küldünk { return(NotFound()); } selectedRent.Performed = rentDTO.Performed; if (selectedRent.Performed) { foreach (RentProductConnection rp in rentedProductsForSelectedRent) { if (selectedRent.Id == rp.RentId) { foreach (Product product in products) { if (rp.ProductModellNumber == product.ModellNumber) { product.Inventory = product.Inventory - rp.CountProduct; if (product.Inventory <= 0) { product.Available = false; } } } } } } _context.SaveChanges(); // elmentjük a módosított épületet return(Ok()); } catch { // Internal Server Error return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public void FinalizeRent(RentDTO rentDTO) { if (rentDTO == null) { throw new ArgumentNullException(nameof(rentDTO)); } RentDTO rentToModify = _rents.FirstOrDefault(r => r.Id == rentDTO.Id); if (rentToModify == null) { throw new ArgumentException("The product does not exist.", nameof(rentDTO)); } rentToModify.Performed = true; _persistence.DoneRentAsync(rentToModify); // jelezzük a változást OnRentChanged(rentDTO.Id); }
private void devolutionMode(RentDTO dto) { SaveRentBtn.Text = "Devolver"; rentId = dto.Id; employee = dto.CustomerInfo; carId = dto.CarId; carInfo = dto.CarInfo; customerInfo = dto.CustomerInfo; fechaDeRenta.Value = Convert.ToDateTime(dto.RentDate); fechaDevolucion.Value = Convert.ToDateTime(dto.DevolutionDate); costPerDay.Value = dto.MontPerDay; CatOfDays.Value = dto.QuantityOfDays; rentComment.Text = dto.Comment; inspectionId = dto.InspectionId; costPerDay.ReadOnly = true; CatOfDays.ReadOnly = true; rentComment.ReadOnly = true; fechaDeRenta.Enabled = false; fechaDevolucion.Enabled = false; }
//ADD public void ProcessRent(RentDTO dto) { if (checkRecord("rents", dto.Id, 1)) { MessageBox.Show("Este registro ya esta en el sistema, operacion invalida!", "Warn"); } else { //Save the rent //Set rent status to 0. cmd.Connection = conexion.AbrirConexion(); cmd.CommandText = "insert into rents values (@inspectionId, @employeeInfo, @carId, @carInfo, @customerInfo, @rent_date, @devolution_date, @mont_x_day, @quantity_of_days, @comment, @status)"; cmd.CommandType = CommandType.Text; FillRentParams(cmd, dto); cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); conexion.CerrarConexion(); //set inspection status to 0. cmd.Connection = conexion.AbrirConexion(); cmd.CommandText = "update inspection set state = 0 where id = " + dto.InspectionId + ""; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); conexion.CerrarConexion(); //Set car status to 0. cmd.Connection = conexion.AbrirConexion(); cmd.CommandText = "update carInfo set status = 0 where id = " + dto.CarId + ""; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); conexion.CerrarConexion(); } }
public void DevolutionProcess(RentDTO dto) { if (checkRecord("rents", dto.Id, 0)) { MessageBox.Show("Este registro ya fue devuelto en el sistema, operacion invalida!", "Warn"); } else { //update rent //set rent status to 1. //add inspection comment as devolucion //update devolution date cmd.Connection = conexion.AbrirConexion(); cmd.CommandText = "update rents set state = 0, comment = 'Comentario de devolucion : " + dto.Comment + "', devolution_date = '" + dto.DevolutionDate + "' where id = " + dto.Id + " "; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); conexion.CerrarConexion(); //set inspection status to 1. cmd.Connection = conexion.AbrirConexion(); cmd.CommandText = "update inspection set state = 1 where id = " + dto.InspectionId + "";// cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); conexion.CerrarConexion(); //Set car status to 1. cmd.Connection = conexion.AbrirConexion(); cmd.CommandText = "update carInfo set status = 1 where id = " + dto.CarId + ""; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); conexion.CerrarConexion(); } }
public IActionResult PutRent([FromBody] RentDTO rentDTO) { try { Rent rent = _context.Rents.FirstOrDefault(r => r.Id == rentDTO.Id); if (rent == null) //ha nincs ilyen azonosítójú => hiba { return(NotFound()); } rent.IsActive = !rentDTO.IsActive; _context.SaveChanges(); //elmentjük a módosított épületet return(Ok()); } catch { // Internal Server Error return(StatusCode(StatusCodes.Status500InternalServerError)); } }