public bool addUser(user temp) { try { db.users.Add(temp); db.SaveChanges(); return true; } catch { db.users.Remove(temp); return false; } }
public ActionResult Registration(RegistrationUserModel temp, bool captchaValid, string captchaErrorMessage) { if (ModelState.IsValid) { if (!captchaValid) { ModelState.AddModelError("recaptcha", captchaErrorMessage); return View(temp); } user newUser = new user(); newUser.login = temp.login; newUser.password = Crypto.HashPassword(temp.password); newUser.admin = false; newUser.email = temp.email; if (dbUser.addUser(newUser)) { return RedirectToAction("LogIn", "User"); } ModelState.AddModelError("", "Login or email address is already taken"); } return View(temp); }