Exemplo n.º 1
0
        public ActionResult Rent(int customerId, int movieId)
        {
            try
            {
                //Removing a rented movie from stock.
                MovieModels RentedMovie = dbMovie.MoviesDb.Where(y => y.MovieID == movieId).FirstOrDefault();
                RentedMovie.QuantityRented++;
                dbMovie.SaveChanges();


                //Find the rented movie and customer by ID
                CustomerModel Customer = db.CustomerDb.Where(x => x.CustomerID == customerId).FirstOrDefault();
                Customer.QuantityOfMovies++;
                db.SaveChanges();

                //Adding movie to rented movelist, unique ID is a string consisting of: "movie id-Customer id"
                CustomerMoviesModell CustMov = new CustomerMoviesModell();
                CustMov.CusMovID = RentedMovie.MovieID.ToString() + '-' + Customer.CustomerID.ToString();
                CustMov.Title    = RentedMovie.Title;
                CustMov.Genre    = RentedMovie.Genre;
                CustMov.Quantity = RentedMovie.QuantityTotalStock - RentedMovie.QuantityRented;
                dbCustMov.CustMovdb.Add(CustMov);
                dbCustMov.SaveChanges();



                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            List <MovieModels> movieList = new List <MovieModels>();
            DataSet            ds        = new DataSet();

            ds.ReadXml(Server.MapPath(xmlPath));
            DataView dv;

            dv      = ds.Tables[0].DefaultView;
            dv.Sort = "Title";
            foreach (DataRowView dr in dv)
            {
                MovieModels model = new MovieModels();
                model.Title       = Convert.ToString(dr[0]);
                model.Description = Convert.ToString(dr[1]);
                model.Length      = Convert.ToInt32(dr[2]);
                model.Year        = Convert.ToInt32(dr[3]);
                model.Genre       = Convert.ToString(dr[4]);
                model.HasSeen     = Convert.ToBoolean(dr[5]);
                model.IsFavourite = Convert.ToBoolean(dr[6]);

                movieList.Add(model);
            }

            if (movieList.Count > 0)
            {
                return(View(movieList));
            }
            return(View());
        }
Exemplo n.º 3
0
        public ActionResult Save(MovieModels movie)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MovieFormViewModel(movie)
                {
                    Genres = _context.Genres.ToList()
                };

                return(View("Movies", viewModel));
            }

            if (movie.Id == 0)
            {
                movie.AddedDate = DateTime.Now;
                _context.Movies.Add(movie);
            }
            else
            {
                var movieInDb = _context.Movies.Single(m => m.Id == movie.Id);
                movieInDb.Name          = movie.Name;
                movieInDb.GenreId       = movie.GenreId;
                movieInDb.NumberInStock = movie.NumberInStock;
                movieInDb.ReleaseDate   = movie.ReleaseDate;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Movies"));
        }
Exemplo n.º 4
0
        // GET: Movie
        public ActionResult Random()
        {
            var movie = new MovieModels {
                Name = "Tiger Zinda Hai"
            };
            //return View(movie);
            //return Content("Hello There!!");
            //return HttpNotFound();
            var Customers = new List <Customer>
            {
                new Customer {
                    Name = "Manish"
                },
                new Customer {
                    Name = "Sarika"
                }
            };

            var viewModel = new RandomMovieViewModel {
                Movie = movie, Customers = Customers
            };

            //return RedirectToAction("Index", "Home", new { Page = 1, Sort = "Name" });
            return(View(viewModel));
        }
Exemplo n.º 5
0
 public MovieFormViewModel(MovieModels movie)
 {
     Id            = movie.Id;
     Name          = movie.Name;
     ReleaseDate   = movie.ReleaseDate;
     NumberInStock = movie.NumberInStock;
     GenreId       = movie.GenreId;
 }
Exemplo n.º 6
0
        public ActionResult DeleteConfirmed(int id)
        {
            MovieModels movieModels = db.Movies.Find(id);

            db.Movies.Remove(movieModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "id,type,name,poster,area,releaseTime,price,remarks")] MovieModels movieModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movieModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(movieModels));
 }
Exemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "ID,Title,ReleaseDate,Genre,Price,Rating")] MovieModels movieModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movieModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(movieModels));
 }
Exemplo n.º 9
0
        public ActionResult Create([Bind(Include = "ID,Title,ReleaseDate,Genre,Price,Rating")] MovieModels movieModels)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movieModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movieModels));
        }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "type,name,poster,area,releaseTime,price,remarks")] MovieModels movieModels)
        {
            if (ModelState.IsValid)
            {
                //默认id,到数据库会自动变成自增长
                movieModels.id = -1;
                db.Movies.Add(movieModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movieModels));
        }
Exemplo n.º 11
0
        public ActionResult EditMovie(MovieModels mm)
        {
            XDocument xDoc  = XDocument.Load(Server.MapPath(xmlPath));
            var       items = (from item in xDoc.Descendants("movie") select item).ToList();

            XElement selected = items.Where(p => p.Element("title").Value == mm.Title.ToString()).FirstOrDefault();

            selected.Remove();
            xDoc.Save(Server.MapPath(xmlPath));
            xDoc.Element("movies").Add(new XElement("movie", new XElement("title", mm.Title), new XElement("description", mm.Description), new XElement("length", mm.Length), new XElement("year", mm.Year), new XElement("genre", mm.Genre), new XElement("hasSeen", mm.HasSeen), new XElement("isFavourite", mm.IsFavourite)));
            xDoc.Save(Server.MapPath(xmlPath));

            return(RedirectToAction("Index", "Movie"));
        }
Exemplo n.º 12
0
        // GET: MovieModels/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MovieModels movieModels = db.Movies.Find(id);

            if (movieModels == null)
            {
                return(HttpNotFound());
            }
            return(View(movieModels));
        }
Exemplo n.º 13
0
 /// <summary>
 /// Deletes a specific item.
 /// </summary>
 /// <param name="item">The item being deleted.</param>
 public void DeleteItem(BaseInventoryModel item)
 {
     // Remove the item from their respective model collection.
     if (item is MovieModel movieModel)
     {
         MovieModels.Remove(movieModel);
     }
     else if (item is BookModel bookModel)
     {
         BookModels.Remove(bookModel);
     }
     else if (item is VideoGameModel videoGameModel)
     {
         VideoGameModels.Remove(videoGameModel);
     }
 }
Exemplo n.º 14
0
        public ActionResult Delete(int id, MovieModels movie)
        {
            try
            {
                //Deletes movie from database
                movie = db.MoviesDb.Where(x => x.MovieID == id).FirstOrDefault();
                db.MoviesDb.Remove(movie);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 15
0
        public ActionResult Create(MovieModels movie)
        {
            try
            {
                // TODO: Add insert logic here

                db.MoviesDb.Add(movie);
                db.SaveChanges();



                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 16
0
        public ActionResult EditMovie(string title)
        {
            MovieModels mm = new MovieModels();

            XDocument xDoc     = XDocument.Load(Server.MapPath(xmlPath));
            var       items    = (from item in xDoc.Descendants("movie") select item).ToList();
            XElement  selected = items.Where(p => p.Element("title").Value == title).FirstOrDefault();

            // TO DO: Description and Genre gets returned with their XELEMENT-tags.
            model.Title       = Convert.ToString(selected.Element("title"));
            model.Description = Convert.ToString(selected.Element("description"));
            model.Length      = int.Parse(selected.Element("length").Value);
            model.Year        = int.Parse(selected.Element("year").Value);
            model.Genre       = Convert.ToString(selected.Element("genre"));
            model.HasSeen     = bool.Parse(selected.Element("hasSeen").Value);
            model.IsFavourite = bool.Parse(selected.Element("isFavourite").Value);

            return(View(model));
        }
Exemplo n.º 17
0
        public ActionResult Edit(int id, MovieModels movie)
        {
            try
            {
                //Edit function for movies in database, can edit movie depending on ID, lets edit quantity, name and Genre

                var Replace = db.MoviesDb.Where(x => x.MovieID == id).FirstOrDefault();
                Replace.QuantityTotalStock = movie.QuantityTotalStock;
                Replace.Genre = movie.Genre;
                db.SaveChanges();



                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 18
0
        // GET: Movie/Random
        public ActionResult Random()
        {
            var movie = new MovieModels()
            {
                Name = "Star Wars"
            };
            var customers = new List <CustomerModels>
            {
                new CustomerModels {
                    Name = "Akira"
                },
                new CustomerModels {
                    Name = "Vig"
                }
            };

            var viewModel = new RandomMovieViewModel()
            {
                Movie     = movie,
                Customers = customers
            };

            return(View(viewModel));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Creates a new dialog window that allows the user to find an item.
        /// </summary>
        /// <param name="itemType">The type of item is bound to the the tab the user is on (i.e searching from the movie tab returns a movie).</param>
        public void FindItem(InventoryItemType itemType)
        {
            // Try to resolve FindItemViewModel.
            if (!(App.ServiceProvider.GetService(typeof(FindItemViewModel)) is FindItemViewModel viewModel))
            {
                return;
            }

            // Create a new button that finds the item.
            UICommand findItemCommand = new UICommand()
            {
                Caption   = "Search",
                IsDefault = true,

                // Only allow the user to find an item if there are no errors in the data entry.
                Command = new DelegateCommand(
                    () => { },
                    () => !string.IsNullOrWhiteSpace(viewModel.Title) && !string.IsNullOrWhiteSpace(viewModel.Platform)
                    )
            };

            // Create a new button that cancels and closes the dialog window for finding an item.
            UICommand cancelCommand = new UICommand()
            {
                Caption  = "Cancel",
                IsCancel = true,
            };

            // Display the dialog window.
            UICommand result = FindItemDialogService?.ShowDialog(
                dialogCommands: new[] { findItemCommand, cancelCommand },
                title: "Find an Item",
                viewModel: viewModel
                );

            // Check if the user executed the find command (clicked the find button).
            if (result != findItemCommand)
            {
                return;
            }

            // Switch based on the tab the user is on.
            switch (itemType)
            {
            case InventoryItemType.Book:
                // Return the first item that has the requested title and platform of the inventory item.
                FocusedItemModel = BookModels.FirstOrDefault(x =>
                                                             string.Equals(x.Title, viewModel.Title, StringComparison.InvariantCultureIgnoreCase) &&
                                                             string.Equals(x.Platform, viewModel.Platform, StringComparison.InvariantCultureIgnoreCase));
                break;

            case InventoryItemType.Movie:
                FocusedItemModel = MovieModels.FirstOrDefault(x =>
                                                              string.Equals(x.Title, viewModel.Title, StringComparison.InvariantCultureIgnoreCase) &&
                                                              string.Equals(x.Platform, viewModel.Platform, StringComparison.InvariantCultureIgnoreCase));
                break;

            case InventoryItemType.VideoGame:
                FocusedItemModel = VideoGameModels.FirstOrDefault(x =>
                                                                  string.Equals(x.Title, viewModel.Title, StringComparison.InvariantCultureIgnoreCase) &&
                                                                  string.Equals(x.Platform, viewModel.Platform, StringComparison.InvariantCultureIgnoreCase));
                break;

            // Throw an exception if our item type does not match any of the models.
            default:
                throw new ArgumentOutOfRangeException();
            }

            // If a model was not found, display a new message box indicating so to the user.
            if (FocusedItemModel == null)
            {
                MessageBoxService?.ShowMessage($"Could not find \"{viewModel.Title}\" on \"{viewModel.Platform}\"");
            }
        }
Exemplo n.º 20
0
        // NOTE: The DevExpress POCO mechanism generates commands for all public methods without parameters or with a single parameter by convention.
        // Corresponding delegate command properties are created using the names of public methods with the suffix "Command".

        /// <summary>
        /// Creates a new dialog window that allows the user to add an item.
        /// </summary>
        /// <param name="itemType">The type of item is bound to the the tab the user is on (i.e adding from the movie tab creates a new movie).</param>
        public void AddItem(InventoryItemType itemType)
        {
            // Get the type of view model we are creating.
            Type viewModelType;

            switch (itemType)
            {
            case InventoryItemType.Book:
                viewModelType = typeof(BookModel);
                break;

            case InventoryItemType.Movie:
                viewModelType = typeof(MovieModel);
                break;

            case InventoryItemType.VideoGame:
                viewModelType = typeof(VideoGameModel);
                break;

            // Throw an exception if our item type does not match any of the models.
            default:
                throw new ArgumentOutOfRangeException();
            }

            // Resolve (create) the view model.
            if (!(App.ServiceProvider.GetService(viewModelType) is BaseInventoryModel viewModel))
            {
                return;
            }

            // Create a new button that adds the item.
            UICommand addItemCommand = new UICommand()
            {
                Caption   = "Add",
                IsDefault = true,

                // Only allow the user to add the item if there are no errors with the data entry.
                Command = new DelegateCommand(
                    () => { },
                    () => string.IsNullOrEmpty(viewModel.Error)
                    )
            };

            // Create a new button that cancels and closes the dialog window for adding an item.
            UICommand cancelCommand = new UICommand()
            {
                Caption  = "Cancel",
                IsCancel = true,
            };

            // Display the dialog window.
            UICommand result = AddOrModifyItemDialogService?.ShowDialog(
                dialogCommands: new[] { addItemCommand, cancelCommand },
                title: "Add a New Item",
                viewModel: viewModel
                );

            // Check if the user executed the add command (clicked the add button).
            if (result != addItemCommand)
            {
                return;
            }

            // Add the new model based on the type of item we are adding.
            switch (itemType)
            {
            case InventoryItemType.Book:
                BookModels.Add(viewModel as BookModel);
                break;

            case InventoryItemType.Movie:
                MovieModels.Add(viewModel as MovieModel);
                break;

            case InventoryItemType.VideoGame:
                VideoGameModels.Add(viewModel as VideoGameModel);
                break;

            // Throw an exception if our item type does not match any of the models.
            default:
                throw new ArgumentOutOfRangeException();
            }

            // Highlight the newly added item.
            FocusedItemModel = viewModel;
        }