public ActionResult Create(RSSUser model) { if (ModelState.IsValid) { Db.users.Add(model); Db.SaveChanges(); return RedirectToAction("Login"); } else { ModelState.AddModelError("", "One or more issues were found with your submission. Please try again."); } //If we got here, it means that the model's state is invalid. Simply return //to the create page and display any errors. return View("Login", model); }
public ActionResult Login(RSSUser model) { int uId = 0; bool found = false; Session["userid"] = null; Session["canwrite"] = false; Session["isadmin"] = false; Session["currentarticle"] = ""; foreach (RSSUser p in Db.users) { if (model.Email == p.Email && model.Password == p.Password) { uId = p.Id; Session["userid"] = p.Id; Session["name"] = p.FirstName + " " + p.LastName; Session["login"] = true; Session["ScrollHeight"] = 0; if (p.isAdmin == true) { Session["isadmin"] = true; } Db.currentUser = p; found = true; if (Db.channels != null) { foreach (channel ch in Db.channels) { ch.isCurrent = false; } } if (Db.users != null) { foreach (RSSUser us in Db.users) { us.currentCategory = null; us.currentChannel = null; us.currentArticle = null; } } if (Db.categories != null) { foreach (Categories cat in Db.categories) { cat.isCurrent = false; } } Db.SaveChanges(); } } if (!found) { foreach (string key in ModelState.Keys) { ModelState[key].Errors.Clear(); } ModelState.AddModelError("", "Invalid User Name / Password"); return View("Login"); } Db.SaveChanges(); //return RedirectToAction("Login"); //return View("MyBlogs", new { model = db.CurrentBlogger }); return RedirectToAction("RSSIndex", "RSS"); }
public ActionResult Edit(RSSUser model) { //again, check modelstate to make sure everything went okay if (ModelState.IsValid) { //Because the item already exists in the DB, we want to tell EF that //one of its models has been changed. We use this somewhat strange syntax to //accomplish this task. Db.Entry(model).State = System.Data.Entity.EntityState.Modified; //Again, the above command adds the request to a queue. To execute the queue, //we need to call SaveChanges() Db.SaveChanges(); //when complete, redirect to Index return RedirectToAction("Index"); } //Things must've went bad, so send back to the Create view. return View("Create", model); }