public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { var user = Database.Find <UserDoc>(u => u.Username.ToLower() == model.Username.ToLower()); if (user == null) { try { user = Database.Insert(model.NewUser()); var identity = user.NewUser(); Response.SaveUserIdentity(identity); return(RedirectToAction("Index", "Home")); } catch { ModelState.AddModelError("", "Couldn't add user to permanent store."); } } else { ModelState.AddModelError("", "User name is already taken."); } } // If we got this far, something failed, redisplay form return(View(model)); }