Exemple #1
0
 private async Task DeleteItemsAsync(IEnumerable <RolePermissionModel> models)
 {
     foreach (var model in models)
     {
         await RolePermissionService.DeleteRolePermissionAsync(model);
     }
 }
        /// <summary>
        /// 保存权限
        /// </summary>
        private void SaveRolePermission()
        {
            List <RolePermission> permissionList = new List <RolePermission>();

            foreach (TreeListNode FNode in treeListPermission.Nodes)
            {
                //加第一级
                if (FNode.Checked == true)
                {
                    AddRolePermission(permissionList, FNode);
                    foreach (TreeListNode SNode in FNode.Nodes)
                    {
                        //加第二级
                        if (SNode.Checked == true)
                        {
                            AddRolePermission(permissionList, SNode);
                            foreach (TreeListNode TNode in SNode.Nodes)
                            {
                                //加第三级
                                if (TNode.Checked == true)
                                {
                                    AddRolePermission(permissionList, TNode);
                                }
                            }
                        }
                    }
                }
            }
            //删除原有的,添加新勾选的
            RolePermissionService.RemoveAndAddRolePermission(RoleCode, permissionList);
        }
Exemple #3
0
        public Result <Role> Get(int roleId)
        {
            var result = new Result <Role>();
            RolePermissionService rolePermissionService = new RolePermissionService();

            result.Value     = rolePermissionService.Get(roleId);
            result.IsSuccess = true;
            return(result);
        }
Exemple #4
0
 private async Task <IList <RolePermissionModel> > GetItemsAsync()
 {
     if (!ViewModelArgs.IsEmpty)
     {
         DataRequest <Data.RolePermission> request = BuildDataRequest();
         return(await RolePermissionService.GetRolePermissionsAsync(request));
     }
     return(new List <RolePermissionModel>());
 }
Exemple #5
0
        public async Task <Result <IList <Role> > > GetAll()
        {
            var result = new Result <IList <Role> >();
            RolePermissionService rolePermissionService = new RolePermissionService();

            result.Value = await rolePermissionService.GetAll();

            result.IsSuccess = true;
            return(result);
        }
        public ActionResult Edit(int id)
        {
            Content c = contentManagerService.Get(id);

            if (!RolePermissionService.CanAccess(c))
            {
                throw new Exception("You do not have permission to access this content.");
            }

            FillViewData(TransformToView(c), c);
            return(View("Editor", viewData));
        }
Exemple #7
0
 public Services()
 {
     UserService            = new UserService();
     ProductService         = new ProductsService();
     CredentialService      = new CredentialService();
     CredentialTypesService = new CredentialTypesService();
     RoleService            = new RoleService();
     RolePermissionService  = new RolePermissionService();
     PermissionService      = new PermissionService();
     UserRoleService        = new UserRoleService();
     CartService            = new CartService();
 }
Exemple #8
0
        public ActionResult Index(int?page, string text, int?catId, int?typeId)
        {
            Load(catId, typeId);
            ViewData["searchText"] = text;
            IList <Content> lstContent = new List <Content>();

            if (RolePermissionService.IsAdmin())
            {
                ViewData["contents"] = contentManagerService.Search(text, catId, typeId).AsPagination(page ?? 1, 10);
            }
            else
            {
                ViewData["contents"] = contentManagerService.Search(text, catId, typeId, (int)Membership.GetUser().ProviderUserKey).AsPagination(page ?? 1, 10);
            }

            return(View(ViewData["contents"]));
        }
        /// <summary>
        /// 加载权限
        /// </summary>
        /// <param name="roleType"></param>
        public void LoadPermission(string roleCode)
        {
            treeListPermission.ClearNodes();
            RoleCode = roleCode;

            SortedList <string, List <Permission> > perList = new SortedList <string, List <Permission> >();

            //所有权限
            perList = RolePermissionService.GetPermissionList(roleCode, out RoleType);
            //获取有勾选的权限
            List <string> roleProList = RolePermissionService.GetSelectPermissionList(roleCode);


            //加载第一级
            foreach (Permission firstPer in perList[string.Empty])
            {
                TreeListNode firstTreeList = treeListPermission.AppendNode(new object[] { firstPer.Name, firstPer.PermissionRemark }, null, firstPer.PermissionCode);

                //加载第二级
                foreach (Permission secoundPer in perList[firstPer.PermissionCode])
                {
                    TreeListNode secoundTreeList = treeListPermission.AppendNode(new object[] { secoundPer.Name, secoundPer.PermissionRemark }, firstTreeList, secoundPer.PermissionCode);

                    //加载第三级
                    foreach (Permission thirdPer in perList[secoundPer.PermissionCode])
                    {
                        TreeListNode thirdTreeList = treeListPermission.AppendNode(new object[] { thirdPer.Name, thirdPer.PermissionRemark }, secoundTreeList, thirdPer.PermissionCode);
                        if (roleProList.Exists(c => c.Equals(thirdPer.PermissionCode)))
                        {
                            thirdTreeList.Checked = true;
                        }
                    }

                    if (roleProList.Exists(c => c.Equals(secoundPer.PermissionCode)))
                    {
                        secoundTreeList.Checked = true;
                    }
                }

                if (roleProList.Exists(c => c.Equals(firstPer.PermissionCode)))
                {
                    firstTreeList.Checked = true;
                }
            }
        }
Exemple #10
0
        public async Task <Result> Delete(Role role)
        {
            var result = new Result();

            try
            {
                RolePermissionService rolePermissionService = new RolePermissionService();
                await rolePermissionService.Delete(role);

                result.IsSuccess = true;
            }
            catch (Exception exception)
            {
                result.IsSuccess     = false;
                result.ExceptionInfo = exception;
            }
            return(result);
        }
 /// <summary>
 /// 删除角色
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void barBtnDeleteRole_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(RoleCode))
         {
             XtraMessageBox.Show("请先选中角色", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else if (XtraMessageBox.Show("是否确定删除", Constants.SYSTEM_PROMPT, MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                  == DialogResult.Yes)
         {
             //判断是否是内置数据
             Role role = RoleService.GetRole(RoleCode);
             List <RolePermission> rolePerList = RolePermissionService.GetRolePermission(c => c.RoleCode == role.RoleCode);
             //内置数据
             if (role.RoleTag)
             {
                 XtraMessageBox.Show("内置数据不可删除", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
             else if (rolePerList != null || rolePerList.Count != 0)
             {
                 XtraMessageBox.Show("此角色还存在权限,不可删除", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
             else
             {
                 RoleService.RemoveRole(RoleCode);
                 //加载所有角色 展示在NavBarGroup中
                 LoadAllRoles();
                 XtraMessageBox.Show("删除成功", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception ex)
     {
         XtraMessageBox.Show(ex.Message, Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        private void SaveData(ContentView content, int[] flavors)
        {
            IList <FashionFlavor> lstFlavors = new List <FashionFlavor>();

            if (flavors != null)
            {
                for (int i = 0; i < flavors.Length; i++)
                {
                    lstFlavors.Add(fashionFlavorRepository.Get(flavors[i]));
                }
            }

            IList <ContentSection> lstSections = new List <ContentSection>();

            foreach (ContentViewSection cs in content.Sections)
            {
                lstSections.Add(new ContentSection {
                    Body = cs.Body, Title = cs.Title, FashionFlavor = cs.FashionFlavor
                });
            }

            if (content.Id == 0)
            {
                contentManagerService.Create(content.Title, content.Body, content.Keywords, content.PromotionalText, new ContentCategory(content.Category.Value), Convert.ToInt32(Membership.GetUser().ProviderUserKey), lstFlavors, lstSections);
            }
            else
            {
                contentManagerService.Edit(content.Id, content.Title, content.Body, content.Keywords, content.PromotionalText, new ContentCategory(content.Category.Value), (ContentType)content.Type, lstFlavors, lstSections);

                // If a editor/author wants to edit a publish content, it should be Send To Verify.
                if (content.Status == ContentStatus.Published && RolePermissionService.CanCreate())
                {
                    contentManagerService.SendToVerify(content.Id, Convert.ToInt32(Membership.GetUser().ProviderUserKey));
                }
            }
        }
        private void FillViewData(ContentView cv, Content c)
        {
            IList <ContentCategory> categories = contentCategoryRepository.GetAll();

            List <SelectListItem> lstPublishers = new List <SelectListItem>();

            string[] users = null;
            MembershipUserCollection membershipUsers = new MembershipUserCollection();

            if (RolePermissionService.IsAuthor())
            {
                users = Roles.GetUsersInRole("editor");
                foreach (string editorName in users)
                {
                    membershipUsers.Add(Membership.GetUser(editorName));
                }
            }

            if (RolePermissionService.IsEditor())
            {
                users = Roles.GetUsersInRole("author");
                foreach (string authorName in users)
                {
                    membershipUsers.Add(Membership.GetUser(authorName));
                }

                users = Roles.GetUsersInRole("publisher");
                foreach (string publisherName in users)
                {
                    membershipUsers.Add(Membership.GetUser(publisherName));
                }
            }

            if (RolePermissionService.IsPublisher())
            {
                users = Roles.GetUsersInRole("editor");
                foreach (string editorName in users)
                {
                    membershipUsers.Add(Membership.GetUser(editorName));
                }
            }

            foreach (MembershipUser mu in membershipUsers)
            {
                SelectListItem item = new SelectListItem();
                item.Text  = mu.UserName;
                item.Value = mu.ProviderUserKey.ToString();
                lstPublishers.Add(item);
            }

            Array typeValues = Enum.GetValues(typeof(ContentType));
            List <SelectListItem> lstContentTypes = new List <SelectListItem>();

            if (c == null && cv.Id != 0)
            {
                c = contentManagerService.Get(cv.Id);
            }

            ContentType type = ContentType.Blog;

            if (c != null)
            {
                type = c.Type;
            }

            SelectListItem itemType = new SelectListItem();

            itemType.Text  = type.ToString();
            itemType.Value = ((int)type).ToString();
            lstContentTypes.Add(itemType);

            IList <FashionFlavor> flavors = fashionFlavorRepository.GetAll();

            if (c == null && cv.Id != 0)
            {
                c = contentManagerService.Get(cv.Id);
            }

            if (c != null)
            {
                viewData.CanApprove = RolePermissionService.CanApprove(c);
                viewData.CanAssign  = RolePermissionService.CanAssignTo(c);
            }

            viewData.Content           = cv;
            viewData.Flavors           = flavors;
            viewData.Publishers        = lstPublishers;
            viewData.ContentTypes      = lstContentTypes;
            viewData.ContentCategories = categories;
        }
Exemple #14
0
 public RolePermissionController()
 {
     _service = new RolePermissionService();
 }