public ActionResult Create(User user) { // WAT GAAT HIER FOUT? try { if (ModelState.IsValid) { user.Photo = "photo.jpg"; user.Bio = ""; user.DateCreated = DateTime.Now; user.PermissionLEvel = 0; user.Votes = 0; db.Users.Add(user); db.SaveChanges(); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { Console.WriteLine(ex.Message); } return RedirectToAction("login", "user"); }
public ActionResult Login(User user) { bool loginCheck = false; User userDetails; try { userDetails = db.Users.First(u => u.Username == user.Username); } catch (Exception ex) { return RedirectToAction("login", "user"); } foreach (var userlist in db.Users) { if (userlist.Username.Equals(user.Username) && userlist.Password.Equals(user.Password)) { loginCheck = true; break; } } Session.Add("login", loginCheck); try { Session.Add("ID", userDetails.User_id); if ( (bool)Session["login"] == true ) { Session.Add("Username", user.Username); if (userDetails.PermissionLEvel == 1) Session.Add("isAdmin", true); return RedirectToAction("index", "home"); } return RedirectToAction("index", "home"); } catch { return RedirectToAction("index", "home"); } }
public ActionResult Edit(int id, User user) { // add lost stuff //var userDetails = db.Users.First(u => u.User_id == user.User_id); // post edits to db try { if (ModelState.IsValid) { db.Entry(user).State = System.Data.EntityState.Modified; db.SaveChanges(); return RedirectToAction("details/" + id.ToString()); } } catch { } return View(); }