public ActionResult ReceiveIt(Reservation reservation)
        {
            //reservation contains only ReservationId and kilometrage
            int id = reservation.ReservationId;
            int kilometrage = reservation.Car.Kilometrage;
            reservation = db.Reservations.Find(id);

                reservation.ReservationStatus = ReservationStatus.Closed;//Todo Consider late delivery
                reservation.DateReturned = DateTime.Now;
                Car car = db.Cars.Find(reservation.Car.CarId);
                car.Kilometrage = kilometrage;
                car.CarStatus = CarStatus.Available;

                db.Entry(reservation).State = EntityState.Modified;
                db.Entry(car).State = EntityState.Modified;
                db.SaveChanges();
                TempData["Added"] = string.Format("{0} Returned", car.Description);
                return RedirectToAction("Index", "Home");

                //db.Entry(reservation).State = EntityState.Modified;
                //TempData["Added"] = reservation.Car.CarModel.Description + " Receive";
                //return RedirectToAction("Index");
            
            //return View(reservation);

        }
Exemple #2
0
 public static ReservationViewModel CreateReservationViewModel(Reservation reservation)
 {
     ApplicationDbContext db = new ApplicationDbContext();
     ReservationViewModel rvm = new ReservationViewModel();
     rvm.Branch = reservation.Branch;
     rvm.CarCode = null;
     return rvm;
 }
        public ActionResult Edit(int? CarId, DateTime StartDate, DateTime EndDate, double Quote)
        {
            if (CarId == null)
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            Car car = db.Cars.Find(CarId);
            if (car == null)
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            
            Reservation reservation = new Reservation();
            reservation.Member = User.Identity.Name;
            reservation.MemberId = User.Identity.GetUserId();
            reservation.CarId = CarId.Value;
            reservation.BranchId = car.BranchId;//This may be redundant because car has the branch field in it
            reservation.FromDate = StartDate;
            reservation.ToDate = EndDate;
            reservation.ReservationStatus = ReservationStatus.Reserved;
            db.Reservations.Add(reservation);
            db.SaveChanges();

            //ViewBag.BranchId = new SelectList(db.Branches, "BranchId", "BranchName", reservation.BranchId);
            //ViewBag.CarId = new SelectList(db.Cars, "CarId", "CarColor", reservation.CarId);
            TempData["Added"] = "Reservation for " + reservation.Car.Description + " Added";
            return RedirectToAction("Index", "Home");
        }
 public ActionResult Edit(Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservation).State = EntityState.Modified;
         reservation.MemberId = ViewBag.UserId;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.BranchId = new SelectList(db.Branches, "BranchId", "BranchName", reservation.BranchId);
     ViewBag.CarId = new SelectList(db.Cars, "CarId", "Description", reservation.CarId);
     ViewBag.MemberId = new SelectList(db.Members, "MemberId", "Member", reservation.MemberId);
     return View(reservation);
 }