public ActionResult Edit([Bind(Include = "position,userId,ladderId")] UserLadder userLadder) { if (Session["currentUser"] == null) { TempData["message"] = "Please login to continue."; return(RedirectToAction("VerifyLogin", "Login")); } try { if (ModelState.IsValid) { db.Entry(userLadder).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } catch { TempData["Message"] = "ERROR - Please try again"; return(View()); } ViewBag.ladderId = new SelectList(db.Ladders, "ladderId", "ladderDescription", userLadder.ladderId); ViewBag.userId = new SelectList(db.Users, "id", "username", userLadder.userId); return(View(userLadder)); }
public ActionResult Create([Bind(Include = "userId,ladderId")] UserLadder userLadder) { if (Session["currentUser"] == null) { TempData["message"] = "Please login to continue."; return(RedirectToAction("VerifyLogin", "Login")); } int currentUser = ((TotalSquashNext.Models.User)Session["currentUser"]).id; var amountOfLadders = (from x in db.LadderRules select x.numLadders).Single(); var usersLadders = (from x in db.UserLadders where x.userId == currentUser select x).Count(); if (usersLadders >= amountOfLadders) { TempData["message"] = "Current rules allow you to be registered on " + amountOfLadders + " ladders at a given time."; return(RedirectToAction("Index", "Ladder")); } userLadder.userId = ((TotalSquashNext.Models.User)Session["currentUser"]).id; try { if (ModelState.IsValid) { db.UserLadders.Add(userLadder); db.SaveChanges(); return(RedirectToAction("Index")); } } catch { TempData["Message"] = "ERROR - Please try again"; return(View()); } ViewBag.ladderId = new SelectList(db.Ladders, "ladderId", "ladderDescription", userLadder.ladderId); //ViewBag.userId = new SelectList(db.Users, "id", "username", userLadder.userId); return(View(userLadder)); }
// GET: UserLadder/Details/5 public ActionResult Details(int?id) { if (Session["currentUser"] == null) { TempData["message"] = "Please login to continue."; return(RedirectToAction("VerifyLogin", "Login")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UserLadder userLadder = db.UserLadders.Find(id); if (userLadder == null) { return(HttpNotFound()); } return(View(userLadder)); }
// GET: UserLadder/Edit/5 public ActionResult Edit(int?id) { if (Session["currentUser"] == null) { TempData["message"] = "Please login to continue."; return(RedirectToAction("VerifyLogin", "Login")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UserLadder userLadder = db.UserLadders.Find(id); if (userLadder == null) { return(HttpNotFound()); } ViewBag.ladderId = new SelectList(db.Ladders, "ladderId", "ladderDescription", userLadder.ladderId); ViewBag.userId = new SelectList(db.Users, "id", "username", userLadder.userId); return(View(userLadder)); }