public ActionResult Login(string accountname, string password) { var model = new LoginVM() { AccountName = accountname, Password = password }; if (ModelState.IsValid) { AccountDao accountDao = new AccountDao(); int result = accountDao.CheckAccount(model.AccountName, CommonBox.StringSecurity.SHA256Encrypt(password)); switch (result) { case -2: ModelState.AddModelError("", Model.Resources.Login.Account_NotTrue); break; case 0: ModelState.AddModelError("", Model.Resources.Login.Account_NotExist); break; case -1: ModelState.AddModelError("", Model.Resources.Login.Account_Locked); break; default: try { var account = db.Accounts.Find(result); if (account.RoleID == 1) { var siteOwner = db.SiteOwners.Where(m => m.AccountID == result).SingleOrDefault(); //Add Session and return Home Page CurrentSiteOwner currentSiteOwner = new CurrentSiteOwner(model.AccountName, siteOwner.SiteOwnerName, siteOwner.AccountID); Session[SessionBox.SITEOWNER_SESSION] = null; Session[SessionBox.SITEOWNER_SESSION] = currentSiteOwner; return(RedirectToAction("Index", "AdminHome", new { area = "Admin" })); } else if (account.RoleID == 2) { var customer = db.Customers.Where(m => m.AccountID == result).SingleOrDefault(); //Add Session and return Home Page CurrentCustomer currentCustomer = new CurrentCustomer(model.AccountName, customer.CustomerName, customer.CustomerID); Session[SessionBox.CUSTOMER_SESSION] = null; Session[SessionBox.CUSTOMER_SESSION] = currentCustomer; return(RedirectToAction("Index", "Home")); } } catch { //Action when account name not single or not found ModelState.AddModelError("", Model.Resources.Login.Account_SomethingWrong); } break; } } return(View(model)); }