public ActionResult DeleteRoleForUser(string UserName, string RoleName) { var account = new AccountController(); var context = new ApplicationDbContext(); ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); if (account.UserManager.IsInRole(user.Id, RoleName)) { account.UserManager.RemoveFromRole(user.Id, RoleName); ViewBag.ResultMessage = "Role removed from this user successfully !"; } else { ViewBag.ResultMessage = "This user doesn't belong to selected role."; } // prepopulat roles for the view dropdown var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList(); ViewBag.Roles = list; var userList = context.Users.OrderBy(r => r.UserName).ToList().Select(rr => new SelectListItem { Value = rr.UserName.ToString(), Text = rr.UserName }).ToList(); ViewBag.Users = userList; return View("ManageUserRoles"); }
public ActionResult List() { var account = new AccountController(); var currentUser = account.UserManager.FindById(User.Identity.GetUserId()); Int64 companyID = -1; if (currentUser.CompanyID > 0) { companyID = currentUser.CompanyID; } return View(this._companyRepository.LoggedInUsersCompanyList(companyID)); }
// // GET: /Company/ public ActionResult Index() { var account = new AccountController(); var currentUser = account.UserManager.FindById(User.Identity.GetUserId()); if (currentUser.CompanyID < 0) { this._companyRepository.LoggedInUsersCompanyList(currentUser.CompanyID); return RedirectToAction("List", "Company"); } return View(); }
public ActionResult Create() { var account = new AccountController(); var currentUser = account.UserManager.FindById(User.Identity.GetUserId()); //user cannot create more than 1 company if (currentUser.CompanyID > 0) { TempData["NoAdditionalCompanyMsg"] = "Sorry. Cannot create additional Companies. Please contact support - [email protected]"; return RedirectToAction("List", "Company"); } return View(); }
public ActionResult AddRoleToUser(string UserName, string RoleName) { var context = new ApplicationDbContext(); ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); var account = new AccountController(); account.UserManager.AddToRole(user.Id, RoleName); ViewBag.ResultMessage = "Role added successfully !"; // prepopulat roles for the view dropdown var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList(); ViewBag.Roles = list; var userList = context.Users.OrderBy(r => r.UserName).ToList().Select(rr => new SelectListItem { Value = rr.UserName.ToString(), Text = rr.UserName }).ToList(); ViewBag.Users = userList; return View("ManageUserRoles"); }
public ActionResult Create(CreateUserViewModel NewUser) { if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = NewUser.UserName }; user.Email = NewUser.EmailId; var account = new AccountController(); var result = account.UserManager.Create(user, NewUser.Password); if (result.Succeeded) { ViewBag.ResultMessage = "User added successfully with BasicAccess Role !"; return RedirectToAction("Index", "User"); } else { ViewBag.ResultMessage = "Error adding user. Please contact System Admin."; } } return RedirectToAction("Index", "User"); }
public ActionResult GetRolesForUser(string UserName) { //string UserName = formCollection["UserName"].ToString(); if (!string.IsNullOrWhiteSpace(UserName)) { var context = new ApplicationDbContext(); ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); var account = new AccountController(); ViewBag.RolesForThisUser = account.UserManager.GetRoles(user.Id); // prepopulat roles for the view dropdown var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList(); ViewBag.Roles = list; var userList = context.Users.OrderBy(r => r.UserName).ToList().Select(rr => new SelectListItem { Value = rr.UserName.ToString(), Text = rr.UserName }).ToList(); ViewBag.Users = userList; } return View("ManageUserRoles"); }
// // GET: /Customer/ public ActionResult Index() { var account = new AccountController(); var currentUser = account.UserManager.FindById(User.Identity.GetUserId()); return View(this._customerRepository.GetCustomers(currentUser.CompanyID)); }