Exemplo n.º 1
0
        private void SetModuleTree(Tree tree, Module module, UserSystem userSystems)
        {
            HashSet <Tree> childTreeSet = new HashSet <Tree>();
            var            modules      = from m in module.Modules
                                          orderby m.ShowOrder
                                          select m;

            foreach (var item in modules)
            {
                if (item != module)
                {
                    Tree   childTree   = new Tree();
                    string moduleID    = item.ModuleID.ToString();
                    var    userModules = UserModuleRepository.GetQueryable().FirstOrDefault(i => i.Module.ModuleID == new Guid(moduleID) && i.UserSystem.UserSystemID == userSystems.UserSystemID);
                    childTree.id         = userModules.UserModuleID.ToString();
                    childTree.text       = "模块:" + item.ModuleName;
                    childTree.@checked   = userModules == null ? false : userModules.IsActive;
                    childTree.attributes = "module";
                    childTreeSet.Add(childTree);
                    if (item.Modules.Count > 0)
                    {
                        SetModuleTree(childTree, item, userSystems);
                    }
                    if (item.Functions.Count > 0)
                    {
                        SetModuleFunTree(childTree, item, userModules);
                    }
                }
            }
            tree.children = childTreeSet.ToArray();
        }
Exemplo n.º 2
0
        private bool UpdateUserPermission(string type, string id, bool isActive)
        {
            bool result = false;

            if (type == "system")
            {
                IQueryable <THOK.Authority.DbModel.UserSystem> queryUserSystem = UserSystemRepository.GetQueryable();
                Guid sid    = new Guid(id);
                var  system = queryUserSystem.FirstOrDefault(i => i.UserSystemID == sid);
                system.IsActive = isActive;
                RoleSystemRepository.SaveChanges();
                result = true;
            }
            else if (type == "module")
            {
                IQueryable <THOK.Authority.DbModel.UserModule> queryUserModule = UserModuleRepository.GetQueryable();
                Guid mid    = new Guid(id);
                var  module = queryUserModule.FirstOrDefault(i => i.UserModuleID == mid);
                module.IsActive = isActive;
                RoleModuleRepository.SaveChanges();
                result = true;
            }
            else if (type == "function")
            {
                IQueryable <THOK.Authority.DbModel.UserFunction> queryUserFunction = UserFunctionRepository.GetQueryable();
                Guid fid    = new Guid(id);
                var  system = queryUserFunction.FirstOrDefault(i => i.UserFunctionID == fid);
                system.IsActive = isActive;
                RoleSystemRepository.SaveChanges();
                result = true;
            }
            return(result);
        }
Exemplo n.º 3
0
 private void InitUserModule(UserSystem userSystem)
 {
     foreach (var module in userSystem.System.Modules)
     {
         var userModules = userSystem.UserModules.Where(um => um.Module.ModuleID == module.ModuleID &&
                                                        um.UserSystem.UserSystemID == userSystem.UserSystemID);
         if (userModules.Count() == 0)
         {
             UserModule um = new UserModule()
             {
                 UserModuleID = Guid.NewGuid(),
                 UserSystem   = userSystem,
                 Module       = module,
                 IsActive     = userSystem.User.UserName == "Admin"
             };
             userSystem.IsActive = userSystem.User.UserName == "Admin";
             SetParentUserModuleIsActiveFalse(um);
             UserModuleRepository.Add(um);
             UserModuleRepository.SaveChanges();
         }
         var userModule = userSystem.UserModules.Single(um => um.Module.ModuleID == module.ModuleID &&
                                                        um.UserSystem.UserSystemID == userSystem.UserSystemID);
         InitUserFunctions(userModule);
     }
 }
Exemplo n.º 4
0
        private bool UpdateUserPermission(string type, string id, string isActive)
        {
            bool result = false;

            if (type == "system")
            {
                IQueryable <AUTH_USER_SYSTEM> queryUserSystem = UserSystemRepository.GetQueryable();
                //Guid sid = new Guid(id);
                var system = queryUserSystem.FirstOrDefault(i => i.USER_SYSTEM_ID == id);
                system.IS_ACTIVE = isActive;
                RoleSystemRepository.SaveChanges();
                result = true;
            }
            else if (type == "module")
            {
                IQueryable <AUTH_USER_MODULE> queryUserModule = UserModuleRepository.GetQueryable();
                // Guid mid = new Guid(id);
                var module = queryUserModule.FirstOrDefault(i => i.USER_MODULE_ID == id);
                module.IS_ACTIVE = isActive;
                RoleModuleRepository.SaveChanges();
                result = true;
            }
            else if (type == "function")
            {
                IQueryable <AUTH_USER_FUNCTION> queryUserFunction = UserFunctionRepository.GetQueryable();
                //Guid fid = new Guid(id);
                var system = queryUserFunction.FirstOrDefault(i => i.USER_FUNCTION_ID == id);
                system.IS_ACTIVE = isActive;
                RoleSystemRepository.SaveChanges();
                result = true;
            }
            return(result);
        }
Exemplo n.º 5
0
        private void SetModuleTree(Tree tree, AUTH_MODULE module, AUTH_USER_SYSTEM userSystems)
        {
            HashSet <Tree> childTreeSet = new HashSet <Tree>();
            var            modules      = from m in module.AUTH_MODULES
                                          orderby m.SHOW_ORDER
                                          select m;

            foreach (var item in modules)
            {
                if (item != module)
                {
                    Tree   childTree = new Tree();
                    string moduleID  = item.MODULE_ID.ToString();
                    //var userModules = UserModuleRepository.GetQueryable().FirstOrDefault(i => i.Module.ModuleID == new Guid(moduleID) && i.UserSystem.UserSystemID == userSystems.UserSystemID);
                    var userModules = UserModuleRepository.GetQueryable().FirstOrDefault(i => i.AUTH_MODULE.MODULE_ID == moduleID && i.AUTH_USER_SYSTEM.USER_SYSTEM_ID == userSystems.USER_SYSTEM_ID);

                    childTree.id   = userModules.USER_MODULE_ID.ToString();
                    childTree.text = "模块:" + item.MODULE_NAME;
                    int a = Convert.ToInt32(userModules.IS_ACTIVE);
                    childTree.@checked   = userModules == null ? false : Convert.ToBoolean(a);
                    childTree.attributes = "module";
                    childTreeSet.Add(childTree);
                    if (item.AUTH_MODULES.Count > 0)
                    {
                        SetModuleTree(childTree, item, userSystems);
                    }
                    if (item.AUTH_FUNCTION.Count > 0)
                    {
                        SetModuleFunTree(childTree, item, userModules);
                    }
                }
            }
            tree.children = childTreeSet.ToArray();
        }
Exemplo n.º 6
0
 private void InitUserModule(AUTH_USER_SYSTEM userSystem)
 {
     foreach (var module in userSystem.AUTH_SYSTEM.AUTH_MODULE)
     {
         var userModules = userSystem.AUTH_USER_MODULE.Where(um => um.AUTH_MODULE.MODULE_ID == module.MODULE_ID &&
                                                             um.AUTH_USER_SYSTEM.USER_SYSTEM_ID == userSystem.USER_SYSTEM_ID);
         if (userModules.Count() == 0)
         {
             AUTH_USER_MODULE um = new AUTH_USER_MODULE()
             {
                 //USER_MODULE_ID = Guid.NewGuid().ToString(),//之后再修改
                 USER_MODULE_ID   = UserModuleRepository.GetNewID("AUTH_USER_MODULE", "USER_MODULE_ID"),
                 AUTH_USER_SYSTEM = userSystem,
                 AUTH_MODULE      = module,
                 IS_ACTIVE        = userSystem.AUTH_USER.USER_NAME == "Admin" ? "1" : "0"
             };
             userSystem.IS_ACTIVE = userSystem.AUTH_USER.USER_NAME == "Admin" ? "1" : "0";
             SetParentUserModuleIsActiveFalse(um);
             UserModuleRepository.Add(um);
             UserModuleRepository.SaveChanges();
         }
         var userModule = userSystem.AUTH_USER_MODULE.Single(um => um.AUTH_MODULE.MODULE_ID == module.MODULE_ID &&
                                                             um.AUTH_USER_SYSTEM.USER_SYSTEM_ID == userSystem.USER_SYSTEM_ID);
         InitUserFunctions(userModule);
     }
 }
Exemplo n.º 7
0
        public object GetUserSystemDetails(string userID, string cityID, string systemID)
        {
            IQueryable <AUTH_SYSTEM>      querySystem     = SystemRepository.GetQueryable();
            IQueryable <AUTH_MODULE>      queryModule     = ModuleRepository.GetQueryable();
            IQueryable <AUTH_USER_SYSTEM> queryUserSystem = UserSystemRepository.GetQueryable();
            IQueryable <AUTH_USER_MODULE> queryUserModule = UserModuleRepository.GetQueryable();
            var            systems           = querySystem.Single(i => i.SYSTEM_ID == systemID);
            var            userSystems       = queryUserSystem.FirstOrDefault(i => i.AUTH_SYSTEM.SYSTEM_ID == systemID && i.AUTH_USER.USER_ID == userID && i.AUTH_CITY.CITY_ID == cityID);
            HashSet <Tree> userSystemTreeSet = new HashSet <Tree>();
            Tree           userSystemTree    = new Tree();

            userSystemTree.id         = userSystems.USER_SYSTEM_ID.ToString();
            userSystemTree.text       = "系统:" + systems.SYSTEM_NAME;
            userSystemTree.@checked   = userSystems.IS_ACTIVE == "1"?true:false;
            userSystemTree.attributes = "system";

            var modules = queryModule.Where(m => m.AUTH_SYSTEM.SYSTEM_ID == systems.SYSTEM_ID && m.MODULE_ID == m.PARENT_AUTH_MODULE.MODULE_ID)
                          .OrderBy(m => m.SHOW_ORDER)
                          .Select(m => m);
            HashSet <Tree> moduleTreeSet = new HashSet <Tree>();

            foreach (var item in modules)
            {
                Tree   moduleTree = new Tree();
                string moduleID   = item.MODULE_ID.ToString();
                //var userModules = queryUserModule.FirstOrDefault(i => i.Module.ModuleID == new Guid(moduleID) && i.UserSystem.UserSystemID == userSystems.UserSystemID);
                var userModules = queryUserModule.FirstOrDefault(i => i.AUTH_MODULE.MODULE_ID == moduleID && i.AUTH_USER_SYSTEM.USER_SYSTEM_ID == userSystems.USER_SYSTEM_ID);

                moduleTree.id   = userModules.USER_MODULE_ID.ToString();
                moduleTree.text = "模块:" + item.MODULE_NAME;
                int a = Convert.ToInt32(userModules.IS_ACTIVE);
                moduleTree.@checked   = Convert.ToBoolean(a);
                moduleTree.attributes = "module";

                moduleTreeSet.Add(moduleTree);
                SetModuleTree(moduleTree, item, userSystems);
                moduleTreeSet.Add(moduleTree);
            }
            userSystemTree.children = moduleTreeSet.ToArray();
            userSystemTreeSet.Add(userSystemTree);
            return(userSystemTreeSet.ToArray());
        }
Exemplo n.º 8
0
        public object GetUserSystemDetails(string userID, string cityID, string systemID)
        {
            IQueryable <THOK.Authority.DbModel.System>     querySystem     = SystemRepository.GetQueryable();
            IQueryable <THOK.Authority.DbModel.Module>     queryModule     = ModuleRepository.GetQueryable();
            IQueryable <THOK.Authority.DbModel.UserSystem> queryUserSystem = UserSystemRepository.GetQueryable();
            IQueryable <THOK.Authority.DbModel.UserModule> queryUserModule = UserModuleRepository.GetQueryable();
            var            systems           = querySystem.Single(i => i.SystemID == new Guid(systemID));
            var            userSystems       = queryUserSystem.FirstOrDefault(i => i.System.SystemID == new Guid(systemID) && i.User.UserID == new Guid(userID) && i.City.CityID == new Guid(cityID));
            HashSet <Tree> userSystemTreeSet = new HashSet <Tree>();
            Tree           userSystemTree    = new Tree();

            userSystemTree.id         = userSystems.UserSystemID.ToString();
            userSystemTree.text       = "系统:" + systems.SystemName;
            userSystemTree.@checked   = userSystems.IsActive;
            userSystemTree.attributes = "system";

            var modules = queryModule.Where(m => m.System.SystemID == systems.SystemID && m.ModuleID == m.ParentModule.ModuleID)
                          .OrderBy(m => m.ShowOrder)
                          .Select(m => m);
            HashSet <Tree> moduleTreeSet = new HashSet <Tree>();

            foreach (var item in modules)
            {
                Tree   moduleTree  = new Tree();
                string moduleID    = item.ModuleID.ToString();
                var    userModules = queryUserModule.FirstOrDefault(i => i.Module.ModuleID == new Guid(moduleID) && i.UserSystem.UserSystemID == userSystems.UserSystemID);
                moduleTree.id         = userModules.UserModuleID.ToString();
                moduleTree.text       = "模块:" + item.ModuleName;
                moduleTree.@checked   = userModules.IsActive;
                moduleTree.attributes = "module";

                moduleTreeSet.Add(moduleTree);
                SetModuleTree(moduleTree, item, userSystems);
                moduleTreeSet.Add(moduleTree);
            }
            userSystemTree.children = moduleTreeSet.ToArray();
            userSystemTreeSet.Add(userSystemTree);
            return(userSystemTreeSet.ToArray());
        }
        public IHttpActionResult PostCataloguesUser(UserCatalogViewModel userCatalogVm)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                UserCatalogRepository relUserCatalogRepo = new UserCatalogRepository(new MyRoomDbContext());
                RelUserCatalogue relUserCatalog  = UserCatalogMapper.CreateModel(userCatalogVm);
                relUserCatalogRepo.InsertUserCatalog(userCatalogVm, true);


                UserModuleRepository relUserModuleRepo = new UserModuleRepository(relUserCatalogRepo.Context);
                List<RelUserModule> userModules = UserModuleMapper.CreateModel(userCatalogVm);
                relUserModuleRepo.InsertUserModule(userModules, userCatalogVm.UserId, true);

                UserCategoryRepository relUserCategoryRepo = new UserCategoryRepository(relUserCatalogRepo.Context);
                List<RelUserCategory> userCategories = UserCategoryMapper.CreateModel(userCatalogVm);
                relUserCategoryRepo.InsertUserCategory(userCategories, userCatalogVm.UserId, true);

                return Ok("Permission Assigned");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }