public ActionResult Create([Bind(Include = "Id,FirstName,LastName")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
// The Bind attribute is used to stop overposting attacks. Include sets a white list of parameters. public ActionResult Create([Bind(Include = "Title,Genre,Duration")] Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movie)); }
public ActionResult Create([Bind(Include = "Id,CustomerId,MovieId,RentalDate,DueDate,ReturnDate")] Rental rental) { if (ModelState.IsValid) { db.Rentals.Add(rental); 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)); }
public void DeleteRental(Rental rental) { using (var videoStore = new VideoStoreContext()) { DeleteRental(videoStore, rental); videoStore.SaveChanges(); } }
public void AddCustomer(string id, string email) { _db.Customer.Add(new Customer { UserId = id, Email = email }); _db.SaveChanges(); }
public void DeleteRentals(IEnumerable <Rental> rentals) { using (var videoStore = new VideoStoreContext()) { foreach (var item in rentals) { DeleteRental(videoStore, item); } videoStore.SaveChanges(); } }
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 })); }