コード例 #1
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            RentalModel rental = db.Rentals.Find(id);

            db.Rentals.Remove(rental);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
 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));
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        // 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));
        }
コード例 #5
0
        // 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));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
 private decimal CalculatePrice(RentalModel rental)
 {
     return((decimal)this.CalculateDays(rental) * rental.Vehicle.PricePerDay);
 }