예제 #1
0
        public ActionResult Create([Bind(Include = "RentId,CustomerId,MovieId,StartDate,EndDate")] RentStats rentStats)
        {
            if (ModelState.IsValid)
            {
                rentStats.StartDate     = DateTime.Now.Date;
                rentStats.StartDatetime = DateTime.Now;
                if (!ValidateDate(rentStats))
                {
                    try
                    {
                        db.RentStats.Add(rentStats);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        TempData["message"] = "Error occured,try again!";
                    }
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerId = new SelectList(db.Customer, "CustomerId", "FirstName", rentStats.CustomerId);
            ViewBag.MovieId    = new SelectList(db.Movie, "MovieId", "Title", rentStats.MovieId);
            return(View(rentStats));
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "RentId,CustomerId,MovieId,StartDate,EndDate")] RentStats rentStats)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rentStats).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId = new SelectList(db.Customer, "CustomerId", "FirstName", rentStats.CustomerId);
     ViewBag.MovieId    = new SelectList(db.Movie, "MovieId", "Title", rentStats.MovieId).OrderBy(x => x.Text).Skip(10000).Take(10000);
     return(View(rentStats));
 }
예제 #3
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentStats rentStats = db.RentStats.Find(id);

            if (rentStats == null)
            {
                return(HttpNotFound());
            }
            return(View(rentStats));
        }
예제 #4
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentStats rentStats = db.RentStats.Find(id);

            if (rentStats == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CustomerId = new SelectList(db.Customer, "CustomerId", "FirstName", rentStats.CustomerId);
            ViewBag.MovieId    = new SelectList(db.Movie, "MovieId", "Title", rentStats.MovieId).OrderBy(x => x.Text);
            return(View(rentStats));
        }
예제 #5
0
        private bool ValidateDate(RentStats rentStats)
        {
            bool error = false;

            if (db.RentStats.Any(x => x.EndDate >= rentStats.StartDate && x.MovieId == rentStats.MovieId && x.CustomerId == rentStats.CustomerId
                                 ) || db.RentStats.Any(x => x.MovieId == rentStats.MovieId && x.EndDate >= rentStats.StartDate))
            {
                error = true;
                TempData["message"] = "The movie is already being rented!";
            }
            if (db.RentStats.Any(x => x.MovieId == rentStats.MovieId && x.StartDate == rentStats.StartDate && x.EndDate == rentStats.EndDate && x.CustomerId == rentStats.CustomerId))
            {
                error = true;
                TempData["message"] = "This rental is a duplicate and already exist";
            }
            if (rentStats.StartDate < DateTime.Now.Date || rentStats.StartDate > DateTime.Now.Date)
            {
                error = true;
                TempData["message"] = "Invalid date!";
            }

            return(error);
        }