public Module Find(int id)
        {
            var module = _repository.FindSingle(u => u.Id == id);

            if (module == null)
            {
                return(new Module());
            }

            return(module);
        }
Пример #2
0
        public void Delete(Guid id)
        {
            var del = _repository.FindSingle(u => u.Id == id);

            if (del == null)
            {
                return;
            }

            _repository.Delete(u => u.CascadeId.Contains(del.CascadeId));
        }
        /// <summary>
        /// 获取带有授权状态的菜单列表
        /// </summary>
        /// <param name="accessType">授权类型,当前有RoleElement/UserElement</param>
        /// <param name="firstId">
        /// 当为RoleElement时,表示RoleId
        /// 当为UserElement时,表示UserId
        /// </param>
        /// <param name="moduleId">模块ID</param>
        public List <ModuleElementVM> LoadWithAccess(string accessType, int firstId, int moduleId)
        {
            //TODO:多个Repository使用的是不同的Context不能进行联表查询,要用UnitOfWork处理

            var listVms = new List <ModuleElementVM>();

            if (moduleId == 0)
            {
                return(listVms);
            }
            string modulename = _moduleRepository.FindSingle(u => u.Id == moduleId).Name;

            foreach (var element in LoadByModuleId(moduleId))
            {
                var accessed = _relevanceRepository.FindSingle(u => u.Key == accessType &&
                                                               u.FirstId == firstId && u.SecondId == element.Id);
                ModuleElementVM vm = new ModuleElementVM
                {
                    Id         = element.Id,
                    Name       = element.Name,
                    ModuleId   = element.ModuleId,
                    DomId      = element.DomId,
                    ModuleName = modulename,
                    Accessed   = accessed != null
                };
                listVms.Add(vm);
            }
            return(listVms);
        }