コード例 #1
0
        public List<PermissionModel> SortPermissionForTree(int parentId, string indexKey = "1")
        {
            var model = new List<PermissionModel>();
            foreach (var p in _permissionService.GetAllPermissionsByParentId(parentId))
            {
                var pm = new PermissionModel
                {
                    Id = p.Id,
                    Name = _permissionService.GetFormattedBreadCrumb(p),
                    ParentId = p.ParentId
                };
                if (parentId == 0)
                {
                    pm.IndexKey = p.Id.ToString();
                }
                else
                {
                    pm.IndexKey = indexKey + "_" + p.Id.ToString();
                }

                pm.ChildPermissions.AddRange(SortPermissionForTree(p.Id, pm.IndexKey));
                model.Add(pm);
            }
            return model;
        }
コード例 #2
0
        protected virtual void PrepareAllPermissionsModel(PermissionModel model)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailablePermissions.Add(new SelectListItem()
            {
                Text = "父权限",
                Value = "0"
            });
            var permissions = _permissionService.GetAllPermission();
            foreach (var p in permissions)
            {
                model.AvailablePermissions.Add(new SelectListItem()
                {
                    Text = _permissionService.GetFormattedBreadCrumb(p),
                    Value = p.Id.ToString()
                });
            }
        }
コード例 #3
0
        public ActionResult Create(PermissionModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var permission = model.ToEntity();
                _permissionService.InsertPermission(permission);

                SuccessNotification("添加成功");
                return continueEditing ? RedirectToAction("Edit", new { id = permission.Id }) : RedirectToAction("List");
            }
            PrepareAllPermissionsModel(model);
            return View(model);
        }
コード例 #4
0
        public ActionResult Edit(PermissionModel model, bool continueEditing)
        {
            var permission = _permissionService.GetPermissionById(model.Id);

            if (ModelState.IsValid)
            {
                permission = model.ToEntity(permission);
                _permissionService.UpdatePermission(permission);

                SuccessNotification("保存成功");
                return continueEditing ? RedirectToAction("Edit", new { id = permission.Id }) : RedirectToAction("List");
            }
            PrepareAllPermissionsModel(model);
            return View(model);
        }
コード例 #5
0
 public ActionResult Create()
 {
     var model = new PermissionModel();
     PrepareAllPermissionsModel(model);
     return View(model);
 }