예제 #1
0
        /// <summary>
        /// 获取用户选择已经拥有的权限
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public ModuleDTOList GetUserPermission(Guid UserID)
        {
            ModuleDTOList mdtolist = new ModuleDTOList();
            var           user     = userRepository.Find(Specification <User> .Eval(u => u.Status == Wings.Domain.Model.Status.Active).And(Specification <User> .Eval(u => u.ID.Equals(UserID))));

            if (user == null)
            {
                return(null);
            }
            //添加用户组模块
            user.Groups.ForEach(g =>
            {
                if (g.Status.Equals(Wings.Domain.Model.Status.Active))
                {
                    g.Modules.ForEach(
                        m =>
                    {
                        mdtolist.Add(Mapper.Map <Module, ModuleDTO>(m));
                    });
                }
            });
            user.Roles.FindAll(t => t.Status == Wings.Domain.Model.Status.Active).ForEach(r =>
            {
                r.Modules.FindAll(m => m.Status == Wings.Domain.Model.Status.Active).ForEach(m =>
                {
                    mdtolist.Add(Mapper.Map <Module, ModuleDTO>(m));
                });
            });
            user.ModuleAllow.FindAll(m => m.Status == Wings.Domain.Model.Status.Active).ForEach(m =>
            {
                mdtolist.Add(Mapper.Map <Module, ModuleDTO>(m));
            });
            //去除重复项
            ModuleDTOList resultmdtolist = new ModuleDTOList();

            mdtolist.GroupBy(m => m.ID).ToList().ForEach(m =>
            {
                resultmdtolist.Add(mdtolist.Find(mt => mt.ID == m.Key));
            });
            //去除禁用的
            user.ModuleBan.FindAll(m => m.Status == Wings.Domain.Model.Status.Active).ForEach(m =>
            {
                if (resultmdtolist.Contains(Mapper.Map <Module, ModuleDTO>(m)))
                {
                    resultmdtolist.Remove(Mapper.Map <Module, ModuleDTO>(m));
                }
            });
            return(resultmdtolist.ToViewModel());
        }
예제 #2
0
        public List <Permission> GetPermissionByUserID(Guid accountid, Guid webid, bool IsAdmin = false)
        {
            List <Permission> plist    = new List <Permission>();
            ModuleDTOList     mdtolist = new ModuleDTOList();
            var user = userRepository.Find(Specification <User> .Eval(u => u.Status == Wings.Domain.Model.Status.Active).And(Specification <User> .Eval(u => u.ID.Equals(accountid))));

            if (user == null)
            {
                return(plist);
            }
            ModuleDTOList resultmdtolist = new ModuleDTOList();

            if (IsAdmin)
            {
                var web = webRepository.Get(Specification <Web> .Eval(w => w.ID.Equals(webid)));
                if (web != null && web.Modules != null)
                {
                    web.Modules.ForEach(m =>
                    {
                        resultmdtolist.Add(Mapper.Map <Module, ModuleDTO>(m));
                    });
                }
            }
            else
            {
                //添加用户组模块
                user.Groups.ForEach(g =>
                {
                    if (g.Status.Equals(Wings.Domain.Model.Status.Active))
                    {
                        g.Modules.ForEach(
                            m =>
                        {
                            mdtolist.Add(Mapper.Map <Module, ModuleDTO>(m));
                        });
                    }
                });
                user.Roles.FindAll(t => t.Status == Wings.Domain.Model.Status.Active).ForEach(r =>
                {
                    r.Modules.FindAll(m => m.Status == Wings.Domain.Model.Status.Active).ForEach(m =>
                    {
                        mdtolist.Add(Mapper.Map <Module, ModuleDTO>(m));
                    });
                });
                user.ModuleAllow.FindAll(m => m.Status == Wings.Domain.Model.Status.Active).ForEach(m =>
                {
                    mdtolist.Add(Mapper.Map <Module, ModuleDTO>(m));
                });
                //去除重复项

                mdtolist.GroupBy(m => m.ID).ToList().ForEach(m =>
                {
                    resultmdtolist.Add(mdtolist.Find(mt => mt.ID == m.Key));
                });
                //去除禁用的
                user.ModuleBan.FindAll(m => m.Status == Wings.Domain.Model.Status.Active).ForEach(m =>
                {
                    //if (resultmdtolist.Contains(Mapper.Map<Module, ModuleDTO>(m)))
                    //{
                    resultmdtolist.RemoveAll(mm => mm.ID.Equals(Mapper.Map <Module, ModuleDTO>(m).ID));
                    //}
                });
            }
            resultmdtolist.ForEach(r => plist.Add(Mapper.Map <ModuleDTO, Permission>(r)));
            return(plist);
        }