コード例 #1
0
        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");
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        //
        // 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();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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");
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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");
        }
コード例 #8
0
 //
 // GET: /Customer/
 public ActionResult Index()
 {
     var account = new AccountController();
     var currentUser = account.UserManager.FindById(User.Identity.GetUserId());
     return View(this._customerRepository.GetCustomers(currentUser.CompanyID));
 }