public ActionResult DeleteConfirmed(int id) { UserComputerGame userComputerGame = db.UserComputerGames.Find(id); db.UserComputerGames.Remove(userComputerGame); db.SaveChanges(); return(RedirectToAction("Index")); }
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)); }
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)); }
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); }
// 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)); }