Beispiel #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());
        }