Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,Phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "MovieID,Title,Director,Genre")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movie));
        }
        public ActionResult Create([Bind(Include = "RentalID,CustomerID,MovieID,DateRented")] Rental rental)
        {
            if (ModelState.IsValid)
            {
                db.Rentals.Add(rental);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", rental.CustomerID);
            ViewBag.MovieID    = new SelectList(db.Movies, "MovieID", "Title", rental.MovieID);
            return(View(rental));
        }
Exemplo n.º 4
0
        public ActionResult RemoveMovieFromUser(List <Guid> filmIds)
        {
            using (var context = new MovieRentalSystemEntities())
            {
                var myId   = GlobalClass.UserId;
                var myself = context.Users.Single(t => t.Id == myId);
                if (myself == null)
                {
                    return(null);
                }

                foreach (var item in filmIds)
                {
                    var movieToRemove = myself.Movies.Single(t => t.Id == item);
                    if (movieToRemove == null)
                    {
                        continue;
                    }

                    movieToRemove.RenterId = null;
                    movieToRemove.IsRented = 0;
                    myself.Movies.Remove(movieToRemove);
                }
                context.SaveChanges();

                return(RefreshMovies());
            }
        }
Exemplo n.º 5
0
        public string SaveMovies(string MovieIds)
        {
            using (var context = new MovieRentalSystemEntities())
            {
                var my = context.Users.Single(usr => usr.Id == GlobalClass.UserId);
                if (my == null)
                {
                    return("not ok");
                }

                var movieSmtg     = MovieIds.Split(',');
                var MovieListGood = new List <Guid>();

                for (int i = 0; i < movieSmtg.Length; i++)
                {
                    movieSmtg[i] = movieSmtg[i].Trim(new Char[] { '"', ']', '[', '\"' });

                    MovieListGood.Add(Guid.Parse(movieSmtg[i]));
                }

                foreach (var item in MovieListGood)
                {
                    var movieToAdd = context.Movies.Single(t => t.Id == item);
                    if (movieToAdd == null)
                    {
                        continue;
                    }
                    movieToAdd.IsRented = 1;
                    movieToAdd.RenterId = my.Id;
                    my.Movies.Add(movieToAdd);
                }
                context.SaveChanges();
                MoviesList.Clear();
                GlobalClass.CartCounter = MoviesList.Count();
                return("ok");
            }
        }