public ActionResult Register(vendorLogin _user) { if (ModelState.IsValid) { var check = db.vendorLogin.FirstOrDefault(s => s.userName == _user.userName); if (check == null) { _user.password = GetMD5(_user.password); db.Configuration.ValidateOnSaveEnabled = false; db.vendorLogin.Add(_user); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } ViewBag.error = "Email already exists"; return(View()); } return(View()); }
public ActionResult vendorLogin(vendorLogin _login, string userName, string password) { if (ModelState.IsValid) //validating the user inputs { var f_password = GetMD5(password); var isExist = false; using (var _entity = new DetergentsEntities()) // out Entity name is "SampleMenuMasterDBEntites" { isExist = _entity.vendorLogin .Any(x => x.userName.Trim().ToLower() == _login.userName.Trim().ToLower() && x.password == f_password); //validating the user name in tblLogin table whether the user name is exist or not if (isExist) { var _loginCredentials = _entity.vendorLogin.ToList() .Where(x => x.userName.Trim().ToLower() == _login.userName.Trim().ToLower()).Select(x => new vendorLogin { userName = x.userName, Id = x.Id, password = x.password }).FirstOrDefault(); // Get the login user details and bind it to LoginModels class //Get the Menu details from entity and bind it in MenuModels list. FormsAuthentication.SetAuthCookie(_loginCredentials.userName, true); // set the formauthentication cookie Session["LoginCredentials"] = _loginCredentials; // Bind the _logincredentials details to "LoginCredentials" session Session["UserName"] = _loginCredentials.userName; return(RedirectToAction("Index", "Vendor")); } ViewBag.ErrorMsg = "Please enter the valid credentials!..."; return(View()); } } return(View()); }