Exemple #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            UserComputerGame userComputerGame = db.UserComputerGames.Find(id);

            db.UserComputerGames.Remove(userComputerGame);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult Update([Bind(Include = "ID,Title,Genre,YearPublished,Price,UserId")] UserComputerGame userComputerGame)
        {
            if (ModelState.IsValid && ValidateUserComputerGame(userComputerGame))
            {
                db.Entry(userComputerGame).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View("Update", userComputerGame));
        }
Exemple #3
0
        public ActionResult Add([Bind(Include = "Title,Genre,YearPublished,Price,UserId")] UserComputerGame userComputerGame)
        {
            if (ModelState.IsValid && ValidateUserComputerGame(userComputerGame))
            {
                userComputerGame.UserId = (int)Session["CurrentUserId"];
                db.UserComputerGames.Add(userComputerGame);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View("Add", userComputerGame));
        }
Exemple #4
0
        private bool ValidateUserComputerGame(UserComputerGame game)
        {
            bool isTitleValid = game.Title.Length > Constants.MIN_STRING_LENGTH &&
                                game.Title.Length < Constants.MAX_NAME_LENGTH;
            bool isGenreValid = game.Genre.Length > Constants.MIN_STRING_LENGTH &&
                                game.Genre.Length < Constants.MAX_GENRE_LENGTH;
            bool isYearValid = game.YearPublished > 0 &&
                               game.YearPublished < Constants.UPPER_YEAR_LIMIT;
            bool isPriceValid = game.Price > 0 &&
                                game.Price < decimal.MaxValue;

            return(isTitleValid && isGenreValid && isYearValid && isPriceValid);
        }
Exemple #5
0
        // GET: UserComputerGames/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserComputerGame userComputerGame = db.UserComputerGames.Find(id);

            if (userComputerGame == null)
            {
                return(HttpNotFound());
            }

            return(View("Delete", userComputerGame));
        }