public ActionResult UserAccountGridViewPartialUpdate(ManageUserViewModel item) { if (ModelState.IsValid) { try { var user = UserManager.FindByName(item.UserName); if (user != null) { string newPassword = item.NewPassword; string newHasPassword = UserManager.PasswordHasher.HashPassword(newPassword); user.PasswordHash = newHasPassword; var check = UserManager.Update(user); if(!check.Succeeded) { ViewData["EditError"] = "Lỗi cập nhập mật khẩu"; } } else { ViewData["EditError"] = "Tên người dùng không tồn tại"; } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else ViewData["EditError"] = "Lổi, kiểm tra thông tin nhập."; var users = userService.GetUsers(); var model = new List<ManageUserViewModel>(); foreach (var user in users) { var u = new ManageUserViewModel(user); var companies = companyService.GetCompaniesByUser(user); u.CompaniesList = companies.ToList(); model.Add(u); } return PartialView("_UserAccountGridViewPartial", model); }
public ActionResult UserAccountGridViewPartialDelete(System.String UserName) { if (UserName != null) { try { var user = UserManager.FindByName(UserName); if (user != null) { UserManager.Delete(user); } else { ViewData["EditError"] = "Tên người dùng không tồn tại"; } // Insert here a code to delete the item from your model } catch (Exception e) { ViewData["EditError"] = e.Message; } } var users = userService.GetUsers(); var model = new List<ManageUserViewModel>(); foreach (var user in users) { var u = new ManageUserViewModel(user); var companies = companyService.GetCompaniesByUser(user); u.CompaniesList = companies.ToList(); model.Add(u); } return PartialView("_UserAccountGridViewPartial",model); }
public ActionResult UserAccountGridViewPartial() { var users = userService.GetUsers(); List<ManageUserViewModel> model = new List<ManageUserViewModel>(); foreach (var user in users) { var u = new ManageUserViewModel(user); var companies = companyService.GetCompaniesByUser(user); u.CompaniesList = companies.ToList(); model.Add(u); } return PartialView("_UserAccountGridViewPartial", model); }