public ActionResult SaveGameFromActiveList (int?id) { //if (Session["UserName"] != null) //{ if (ModelState.IsValid) { var userGames = Session["ActiveGames"] as UserActiveGames; var g = userGames.findGame(id); // make a copy of the object to avoid the circular // ref issue UserGame newSavedGame = new UserGame(g); // check if there is a matching game in the DB var existingGame = db.UserGames. Where(u => u.UserGameID == g.UserGameID). FirstOrDefault(); if (existingGame == null) { db.UserGames.Add(newSavedGame); string sessionUserName = Session["UserName"].ToString(); var user = db.Users. Where(u => u.Email == sessionUserName). First(); if (user != null) { user.UserGames.Add(newSavedGame); db.Entry(user).State = EntityState.Modified; } } // if the game is already saved // we need to update the existing the game else { existingGame.Cells = g.Cells; db.Entry(existingGame).State = EntityState.Modified; } db.SaveChanges(); // the game now needs to be removed from active games userGames.removeGame(g); return(RedirectToAction("ListSavedGames")); //return RedirectToAction("Index"); } //} return(View()); }
public ActionResult Edit([Bind(Include = "UserID,Email,Password,FirstName,LastName,IsAdmin")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create( UserTemplate userTemplate) { // TODO: // check the session is still valid // find the matching User in the DB // associate the Template with the User in the DB // by adding the Template to the User object Template // Collection //if (Session["Name"] != null) //{ if (ModelState.IsValid) { db.UserTemplates.Add(userTemplate); string sessionUserName = Session["UserName"].ToString(); var user = db.Users. Where(u => u.Email == sessionUserName). First(); if (user != null) { user.UserTemplates.Add(userTemplate); db.Entry(user).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } //} ViewBag.UserID = new SelectList(db.Users, "UserID", "Email", userTemplate.UserID); return(View(userTemplate)); }