Ejemplo n.º 1
0
        public ActionResult Detail(Guid?id)
        {
            if (id == null)
            {
                GetAlert(Danger, "ID cannot e null!");
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var role = TheRoleManager.GetRoleById(id);

            if (role == null)
            {
                GetAlert(Danger, "Role cannot be found!");
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            var model = new RoleVm.Detail()
            {
                RoleId          = role.RoleId,
                RoleName        = role.Name,
                RoleDescription = role.Description,
                RoleEnabled     = role.Enabled,
                RoleLocked      = role.Locked
            };
            var roleUsers  = TheRoleManager.GeUsersInRole(id);
            var userDetail = roleUsers.Select(x => new RoleVm.RoleUsersDetail()
            {
                UserId   = x.UserId,
                UserName = x.User.Name
            }).ToList();

            model.RoleUsersDetail = userDetail;
            return(View("Detail", model));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                GetAlert(Danger, "ID cannot be null!");
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var user = TheUserManager.GetUserById(id);

            if (user == null)
            {
                GetAlert(Danger, "User cannot be found!");
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            var model = new UserVm.Edit()
            {
                UserId      = user.UserId,
                UserName    = user.Name,
                UserEnabled = user.Enabled,
                UserLocked  = user.Locked
            };
            var userRoles  = TheUserManager.GetRolesForUser(id);
            var roles      = TheRoleManager.GetAllRoles();
            var roleDetail = roles.Select(rd => new CheckBoxListItem()
            {
                Id        = rd.RoleId,
                Display   = rd.Name,
                IsChecked = userRoles.Any(ur => ur.RoleId == rd.RoleId)
            }).ToList();

            model.Roles = roleDetail;
            return(View("Edit", model));
        }
Ejemplo n.º 3
0
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                GetAlert(Danger, "ID cannot be null!");
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var role = TheRoleManager.GetRoleById(id);

            if (role == null)
            {
                GetAlert(Danger, "Role cannot be found!");
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            var model = new RoleVm.Delete()
            {
                RoleId      = role.RoleId,
                Name        = role.Name,
                Description = role.Description,
                RoleEnabled = role.Enabled,
                RoleLocked  = role.Locked
            };

            return(View("Delete", model));
        }
Ejemplo n.º 4
0
 public ActionResult Create(RoleVm.Create model)
 {
     if (ModelState.IsValid)
     {
         TheRoleManager.CreateRole(model.RoleName, model.RoleDescription);
         GetAlert(Success, "Role created!");
         return(RedirectToAction("Index"));
     }
     GetAlert(Danger, "Error!");
     return(View("Create", model));
 }
Ejemplo n.º 5
0
 public ActionResult Delete(RoleVm.Delete model)
 {
     if (ModelState.IsValid)
     {
         TheRoleManager.DeleteRole(model.RoleId);
         GetAlert(Success, "Role deleted!");
         return(RedirectToAction("Index"));
     }
     GetAlert(Danger, "Error!");
     return(View("Delete", model));
 }
Ejemplo n.º 6
0
 public ActionResult Edit(RoleVm.Edit model)
 {
     if (ModelState.IsValid)
     {
         TheRoleManager.UpdateRole(model.RoleId, model.RoleName, model.RoleDescription, model.RoleEnabled, model.RoleLocked);
         GetAlert(Success, "Role updated!");
         return(RedirectToAction("Index"));
     }
     GetAlert(Danger, "Error!");
     return(View("Edit", model));
 }
Ejemplo n.º 7
0
        public ActionResult Create()
        {
            var model      = new UserVm.Create();
            var roles      = TheRoleManager.GetAllRoles();
            var roleDetail = roles.Select(rd => new CheckBoxListItem()
            {
                Id        = rd.RoleId,
                Display   = rd.Name,
                IsChecked = false
            }).ToList();

            model.Roles = roleDetail;
            return(View("Create", model));
        }
Ejemplo n.º 8
0
        public ActionResult Index(string term, int?page)
        {
            var model = TheRoleManager.GetAllRoles().Select(x => new RoleVm.Index()
            {
                RoleId          = x.RoleId,
                RoleName        = x.Name,
                RoleDescription = x.Description,
                RoleUserCount   = x.UserRoles.Count,
                RoleLocked      = x.Locked,
                RoleEnabled     = x.Enabled
            });

            if (!string.IsNullOrEmpty(term))
            {
                model = model.Where(s => s.RoleName.Contains(term) || s.RoleDescription.Contains(term));
            }

            var pageNo    = page ?? 1;
            var pagedData = model.ToPagedList(pageNo, AppConfig.PageSize);

            ViewBag.Data = pagedData;

            return(View("Index", pagedData));
        }