public IActionResult Register(UserRegistrationModel userModel) { try { if (!ModelState.IsValid) { return(View(userModel)); } List <Account> lstacc = AccountRes.GetAll(); int countAcc = 0; for (int i = 0; i < lstacc.Count; i++) { if (lstacc[i].username == userModel.Username) { countAcc = 1; } } if (countAcc == 1) { ModelState.AddModelError("1", "UserName already exists! Please try another."); } else { int resultAcc = AccountRes.InsertRegisterAccount(userModel.Username, userModel.Password); int resultDetails = AccountRes.InsertRegisterDetails(userModel.Username, userModel.FullName, userModel.Email, userModel.PhoneNumber, userModel.Address, resultAcc); return(RedirectToAction("Index", "HomeDrugstore")); } } catch (Exception ex) { Console.Write(ex); } return(View()); }
public IActionResult DeleteAccount(int id) { object[] value = { id }; var errorCode = 0; var errorMessage = ""; string[] output = { }; var result = AccountRes.DeleteAccount(value, ref output, ref errorCode, ref errorMessage); if (result) { return(RedirectToAction("ListAccount")); } return(Content("loi" + errorMessage)); }
public IActionResult Login(UserLoginModel userModel, string returnUrl = null) { try { // Verification. if (ModelState.IsValid) { List <Account> lst = AccountRes.GetAll(); string usertemp = ""; for (int i = 0; i < lst.Count; i++) { if ((lst[i].username == userModel.Username) && (lst[i].password == userModel.Password)) { usertemp = lst[i].username; DEntity <AccountDetail> e = new DEntity <AccountDetail>(ConstValue.ConnectionString, AccountDetail.getTableName()); AccountDetail lstDetail = e.get("iduser", lst[i].id); this.SignInUser(lst[i].id, lst[i].groupId, lst[i].username, lstDetail.name, userModel.RememberMe); Console.WriteLine("user", User.Identity.Name); //Console.WriteLine("userdata", claims[1].Value); Console.WriteLine("user", User.Identity.AuthenticationType); return(this.RedirectToAction("Index", "HomeDrugstore")); } } if (usertemp == "") { ModelState.AddModelError(string.Empty, "Invalid username or password."); } } } catch (Exception ex) { Console.Write(ex); } // If we got this far, something failed, redisplay form return(this.View(userModel)); }
public IActionResult ListAccount() { List <Account> lst = AccountRes.GetAll(); return(View(lst)); }