示例#1
0
        public GetAllModuleResponse GetAllModules(GetAllModuleRequest request)
        {
            GetAllModuleResponse response = new GetAllModuleResponse();

            try
            {
                IEnumerable <Module> modules = _moduleRepository.FindAll();

                response.ModuleViews = modules.ConverToModuleViews();
            }
            catch (Exception ex)
            {
                string message = "查询失败!错误信息:/n" + ex.Message;
                response = new GetAllModuleResponse()
                {
                    ResponseSucceed = false,
                    Message         = "查询失败"
                };
                LoggingFactory.GetLogger().WriteDebugLogger(message);

                return(response);
            }

            return(response);
        }
示例#2
0
        public IEnumerable <ModuleDTO> GetModules()
        {
            var modules = moduleRepo.FindAll();
            List <ModuleDTO> moduleDTOs = new List <ModuleDTO>();

            Mapper.Initialize(c => c.CreateMap <DbSet <Module>, List <ModuleDTO> >());
            moduleDTOs = Mapper.Map <List <ModuleDTO> >(modules);

            return(moduleDTOs);
        }
        private void SetForeignKeyForDataPiont()
        {
            IEnumerable <Module> modules = _moduleRepository.FindAll();

            foreach (Module module in modules)
            {
                foreach (KeyValuePair <int, DataPoint> dataPointKeyValuePair in _dataPointsFromConfigFile)
                {
                    if (module.Number == dataPointKeyValuePair.Value.ModuleBelongTo.Number)
                    {
                        //ModuleBelongTo.Id是DataPoint的外键
                        dataPointKeyValuePair.Value.ModuleBelongTo.Id = module.Id;
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// 授予用户权限
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="moduleids"></param>
        /// <param name="IsBan">是否禁用</param>
        /// <returns></returns>
        public void AssignUserPermission(Guid userid, Guid webid, List <Guid> moduleids, bool IsBan)
        {
            List <Module> modules = moduleRepository.FindAll(Specification <Module> .Eval(m => moduleids.Contains(m.ID)).And(Specification <Module> .Eval(m => m.Web.ID.Equals(webid)))).ToList();
            var           user    = userRepository.Find(Specification <User> .Eval(u => u.ID.Equals(userid)));

            if (IsBan)//是否是禁用
            {
                var tempBanmodules   = user.ModuleBan;
                var tempAllowmodules = user.ModuleAllow;
                user.ModuleAllow = null;
                user.ModuleBan   = null;
                if (tempBanmodules != null)
                {
                    tempBanmodules.RemoveAll(t => t.Web.ID.Equals(webid));
                }
                //去除特设允许
                if (tempAllowmodules != null)
                {
                    tempAllowmodules.RemoveAll(t => moduleids.Contains(t.ID));
                }
                tempBanmodules.AddRange(modules);
                user.ModuleBan   = tempBanmodules;
                user.ModuleAllow = tempAllowmodules;
            }
            else
            {
                var tempmodules = user.ModuleAllow;

                user.ModuleAllow = null;
                if (tempmodules != null)
                {
                    tempmodules.RemoveAll(t => t.Web.ID.Equals(webid));
                }
                List <Guid> HaveYet = new List <Guid>();
                if (user.Roles != null)
                {
                    user.Roles.ForEach(r =>
                    {
                        //if (r.Status == Wings.Domain.Model.Status.Active)
                        {
                            if (r.Modules != null)
                            {
                                r.Modules.ForEach(m =>
                                {
                                    if (m.Web.ID.Equals(webid))
                                    {
                                        HaveYet.Add(m.ID);
                                    }
                                });
                            }
                        }
                    }
                                       );
                }
                if (user.Groups != null)
                {
                    user.Groups.ForEach(g =>
                    {
                        //if (g.Status == Wings.Domain.Model.Status.Active)
                        {
                            if (g.Modules != null)
                            {
                                g.Modules.ForEach(m =>
                                {
                                    if (m.Web.ID.Equals(webid))
                                    {
                                        HaveYet.Add(m.ID);
                                    }
                                });
                            }
                        }
                    });
                }
                if (modules != null)
                {
                    modules.RemoveAll(m => HaveYet.Contains(m.ID));
                    tempmodules.AddRange(modules);
                }
                user.ModuleAllow = tempmodules;
            }
            userRepository.Update(user);
            //调用用户权限跟新
            user.UpdatePermission(webid);
            Context.Commit();//提交当前事务单元
            bus.Commit();
        }
 public List <ModuleDTO> ListAll()
 {
     return(_Repository.FindAll().OrderBy(x => x.SortOrder).Select(x => x.ToDto()).ToList());
 }