public ActionResult Login(UserRegistrationVM UR) { if (string.IsNullOrEmpty(UR.UserName) || string.IsNullOrEmpty(UR.UserName)) { ViewBag.ErrorMessage = "Please fill mandatory fields"; return(View()); } var password = UR.Encrypt(UR.Password); var output = _db.tblusers.FirstOrDefault(obj => obj.username == UR.UserName && obj.passwordHash == password && obj.role_id.Value != 2); if (output != null) { FormsAuthentication.SetAuthCookie(UR.UserName, true); Session["UserName"] = UR.UserName.ToUpper(); return(RedirectToAction("Home", "Home")); } else { ViewBag.ErrorMessage = "Invalid Credentials!"; return(View()); } }
public ActionResult Create(tbluser obj) { var CustomerMasterlist = repo1.GetAllUsers(); try { if (ModelState.IsValid) { if (CustomerMasterlist.Where(ite => ite.username.ToLower() == obj.username.ToLower()).FirstOrDefault() != null) { ViewBag.ErrorMsg = "User already exists"; t.roles = repo1.GetAllRole(); return(View(t)); } else { obj.passwordHash = vm.Encrypt(obj.passwordHash); repo1.Insert(obj); ViewBag.SuccessMsg = "Record Added Successfully"; CustomerMasterlist = repo1.GetAllUsers(); return(RedirectToAction("Listing")); } } else { t.roles = repo1.GetAllRole(); return(View(t)); } } catch (Exception ex) { ViewBag.ErrorMsg = "Sorry Some Problem Occured" + ex.ToString(); } return(RedirectToAction("Listing")); }