public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus = MembershipCreateStatus.Success; //Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); if (db.Users.Any(u => u.UserName == model.UserName)) { createStatus = MembershipCreateStatus.DuplicateUserName; } if (createStatus == MembershipCreateStatus.Success) { db.Users.Add(new User() { UserName = model.UserName, EMail = model.Email, Password = model.Password }); db.SaveChanges(); } if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); }
private ActionResult UpOrDown(int id, string r, bool up) { var user = db.Users.Single(u => u.UserName == User.Identity.Name); var msq = db.Msqs.Find(id); var vote = db.Votes.SingleOrDefault(v => v.UserId == user.UserId && v.MsqId == id); if (vote == null) { vote = new Vote() { MsqId = id, UserId = user.UserId }; db.Votes.Add(vote); } vote.Up = up; db.SaveChanges(); return(Redirect(r)); }