public ActionResult DeleteConfirmed(Guid id) { RentalModel rental = db.Rentals.Find(id); db.Rentals.Remove(rental); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,RentedAt,ReturnedAt,VehicleId,ClientId")] RentalModel rental) { if (ModelState.IsValid) { db.Entry(rental).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClientId = new SelectList(db.Clients, "Id", "FirstName", rental.ClientId); ViewBag.VehicleId = new SelectList(db.Vehicles, "Id", "LicensePlate", rental.VehicleId); return(View(rental)); }
public ActionResult Create([Bind(Include = "Id,RentedAt,ReturnedAt,VehicleId,ClientId")] RentalModel rental) { if (ModelState.IsValid) { rental.Id = Guid.NewGuid(); db.Rentals.Add(rental); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClientId = new SelectList(db.Clients, "Id", "FirstName", rental.ClientId); ViewBag.VehicleId = new SelectList(db.Vehicles, "Id", "LicensePlate", rental.VehicleId); return(View(rental)); }
// GET: Rentals/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RentalModel rental = db.Rentals.Find(id); if (rental == null) { return(HttpNotFound()); } return(View(rental)); }
// GET: Rentals/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RentalModel rental = db.Rentals.Find(id); if (rental == null) { return(HttpNotFound()); } ViewBag.ClientId = new SelectList(db.Clients, "Id", "FirstName", rental.ClientId); ViewBag.VehicleId = new SelectList(db.Vehicles, "Id", "LicensePlate", rental.VehicleId); return(View(rental)); }
private decimal CalculateDays(RentalModel rental) { var latestDate = rental.ReturnedAt == null ? DateTime.Now : rental.ReturnedAt.Value; return((decimal)Math.Ceiling((latestDate.Date - rental.RentedAt.Date).TotalDays)); }
private decimal CalculatePrice(RentalModel rental) { return((decimal)this.CalculateDays(rental) * rental.Vehicle.PricePerDay); }