Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        // 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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
 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();
        }
Ejemplo n.º 6
0
        public void DeleteRentals(IEnumerable <Rental> rentals)
        {
            using (var videoStore = new VideoStoreContext())
            {
                foreach (var item in rentals)
                {
                    DeleteRental(videoStore, item);
                }

                videoStore.SaveChanges();
            }
        }
Ejemplo n.º 7
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 }));
        }