public ActionResult Register(RegistrationModel model) { LogManager logManager = new LogManager(db); if (ModelState.IsValid) { UserManager userManger = new UserManager(db); if (!userManger.IsLoginNameExist(model)) { userManger.createNewUser(model); //FormsAuthentication.SetAuthCookie(model.UserName, false); logManager.LogSuccessfulRegistration(model.UserName); InsertMessage message = new InsertMessage(); // passing message to control about seccussfull registration message.MessageText = "Registered user: "******" successfully. Now you can Log In."; TempData["message"] = message; return RedirectToAction("Index", "Home"); } else { logManager.LogUnSuccessfulRegistration(model.UserName); ModelState.AddModelError("", "Username already exists"); } } logManager.LogUnSuccessfulRegistration(model.UserName); return View(); }
// Check Using RegistrationModel public bool IsLoginNameExist(RegistrationModel loginModel) { string userName = loginModel.UserName; // Check if username exists in database return db.Logins.Any(x => x.UserName.ToLower().Equals(userName)); }