コード例 #1
0
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
コード例 #2
0
ファイル: MoviesController.cs プロジェクト: manx/VideoStore
 public ActionResult Edit([Bind(Include = "Id,Title,Genre,Duration")] Movie movie)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(movie));
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,CustomerId,MovieId,RentalDate,DueDate,ReturnDate")] Rental rental)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rental).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", rental.CustomerId);
     ViewBag.MovieId    = new SelectList(db.Movies, "Id", "Title", rental.MovieId);
     return(View(rental));
 }
コード例 #4
0
        private void DeleteRental(VideoStoreContext videoStore, Rental rental)
        {
            ++rental.Movie.NumOfCopies;

            videoStore.Movies.Attach(rental.Movie);
            videoStore.Entry(rental.Movie).Property(m => m.NumOfCopies).IsModified = true;

            rental.User  = null;
            rental.Movie = null;

            videoStore.Rentals.Attach(rental);
            videoStore.Rentals.Remove(rental);
        }
コード例 #5
0
        private void AddRental(VideoStoreContext videoStore, Rental rental)
        {
            var rentedMovie = new RentedMovie
            {
                MovieId = rental.MovieId,
                UserId  = rental.UserId,
            };

            --rental.Movie.NumOfCopies;
            videoStore.Movies.Attach(rental.Movie);
            videoStore.Entry(rental.Movie).Property(m => m.NumOfCopies).IsModified = true;

            rental.Movie = null;
            rental.User  = null;
            videoStore.Rentals.Add(rental);

            videoStore.RentedMovies.Add(rentedMovie);
        }
コード例 #6
0
        public ActionResult SubmitReview(VideoReview model)
        {
            // either update or add new review entry to model, depending on whether it exists already.
            // a user can only have one review for a video.
            if (model.ReviewId == 0)
            {
                _db.VideoReview.Add(model);
            }
            else
            {
                _db.VideoReview.Attach(model);
                var entry = _db.Entry(model);
                entry.Property(i => i.Review).IsModified = true;
                entry.Property(i => i.Rating).IsModified = true;
            }

            _db.SaveChanges();
            return(RedirectToAction("SingleVideo", "Home", new { inventoryId = model.InventoryId }));
        }