コード例 #1
0
ファイル: RightsServer.cs プロジェクト: little-fatter/sanhu
        public string Save(RightsMasterType masterType, string masterId, RightsSaveModel value)
        {
            DbContext dbContext = dbContext_0;

            string     text        = (masterType == RightsMasterType.User) ? "user" : "role";
            core_right core_rights = dbContext.FirstOrDefault <core_right>("where masterType = @0 and masterId = @1", new object[2]
            {
                text,
                masterId
            });
            bool flag = core_rights == null;

            if (core_rights == null)
            {
                core_rights              = new core_right();
                core_rights.ID           = Guid.NewGuid().ToString();
                core_rights.CreateDate   = DateTime.Now;
                core_rights.CreateUserID = SysContext.WanJiangUserID;
                core_rights.MasterType   = text;
                core_rights.MasterID     = masterId;
            }
            core_rights.ModifyDate   = DateTime.Now;
            core_rights.ModifyUserID = SysContext.WanJiangUserID;
            core_rights.RightsValue  = JsonHelper.SerializeObject(value);
            if (flag)
            {
                dbContext.Insert(core_rights);
            }
            else
            {
                dbContext.Update(core_rights);
            }
            return(core_rights.ID);
        }
コード例 #2
0
ファイル: RightsServer.cs プロジェクト: little-fatter/sanhu
        public RightsModel Get(RightsMasterType masterType, string masterId)
        {
            DbContext dbContext = dbContext_0;

            if (masterType != RightsMasterType.Role)
            {
            }
            RightsModel rightsModel                = new RightsModel();
            List <core_funRightsRule>   list       = dbContext.Fetch <core_funRightsRule>("where RuleEnabled = 1", new object[0]);
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("enabledVisit", "访问");
            dictionary.Add("enabledAdd", "新增");
            dictionary.Add("enabledEdit", "编辑");
            dictionary.Add("enabledDel", "删除");
            dictionary.Add("enabledImport", "导入");
            dictionary.Add("enabledExport", "导出");
            dictionary.Add("enabledPrint", "打印");
            Dictionary <string, string> dictionary2 = dictionary;
            List <string> list2 = new List <string>();

            foreach (core_funRightsRule item in list)
            {
                string        modelName     = item.ModelName;
                ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(modelName);
                if (!rightsModel.funRights.Any((RightsDataModel a) => a.modelName == modelName))
                {
                    List <object> list3 = new List <object>();
                    if (item.EnabledVisit == 1)
                    {
                        list3.Add(new
                        {
                            id   = "enabledVisit",
                            text = dictionary2["enabledVisit"]
                        });
                        list2.Add("enabledVisit");
                    }
                    if (item.EnabledAdd == 1)
                    {
                        list3.Add(new
                        {
                            id   = "enabledAdd",
                            text = dictionary2["enabledAdd"]
                        });
                        list2.Add("enabledAdd");
                    }
                    if (item.EnabledEdit == 1)
                    {
                        list3.Add(new
                        {
                            id   = "enabledEdit",
                            text = dictionary2["enabledEdit"]
                        });
                        list2.Add("enabledEdit");
                    }
                    if (item.EnabledDel == 1)
                    {
                        list3.Add(new
                        {
                            id   = "enabledDel",
                            text = dictionary2["enabledDel"]
                        });
                        list2.Add("enabledDel");
                    }
                    if (item.EnabledImport == 1)
                    {
                        list3.Add(new
                        {
                            id   = "enabledImport",
                            text = dictionary2["enabledImport"]
                        });
                        list2.Add("enabledImport");
                    }
                    if (item.EnabledExport == 1)
                    {
                        list3.Add(new
                        {
                            id   = "enabledExport",
                            text = dictionary2["enabledExport"]
                        });
                        list2.Add("enabledExport");
                    }
                    if (item.EnabledPrint == 1)
                    {
                        list3.Add(new
                        {
                            id   = "enabledPrint",
                            text = dictionary2["enabledPrint"]
                        });
                        list2.Add("enabledPrint");
                    }
                    if (!string.IsNullOrEmpty(item.EnabledButtons))
                    {
                        List <SelectionItem> list4 = JsonHelper.DeserializeJsonToList <SelectionItem>(item.EnabledButtons);
                        if (list4 != null)
                        {
                            list3.AddRange(list4);
                        }
                    }
                    if (serviceConfig == null)
                    {
                        rightsModel.funRights.Add(new RightsDataModel
                        {
                            modelName   = item.ModelName,
                            modelTitle  = item.ModelName,
                            rules       = list3,
                            rightsValue = string.Join(";", list2)
                        });
                    }
                    else
                    {
                        rightsModel.funRights.Add(new RightsDataModel
                        {
                            modelName   = serviceConfig.model.name,
                            modelTitle  = serviceConfig.model.title,
                            moduleName  = serviceConfig.model.moduleName,
                            moduleTitle = serviceConfig.model.moduleTitle,
                            rules       = list3,
                            rightsValue = string.Join(";", list2)
                        });
                    }
                }
            }
            List <core_dataRightsRule> source = dbContext.Fetch <core_dataRightsRule>("where RuleEnabled = 1", new object[0]);
            List <string> list5 = source.Select(r => r.ModelName).Distinct().ToList();

            foreach (string item2 in list5)
            {
                ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(item2);
                if (serviceConfig != null)
                {
                    List <core_dataRightsRule> list6 = (from a in source
                                                        where a.ModelName == item2
                                                        select a).ToList();
                    List <object> list3 = new List <object>();
                    foreach (core_dataRightsRule item3 in list6)
                    {
                        if (item3 != null)
                        {
                            list3.Add(new
                            {
                                id   = item3.ID,
                                text = item3.Title
                            });
                        }
                    }
                    rightsModel.dataRights.Add(new RightsDataModel
                    {
                        modelName   = serviceConfig.model.name,
                        modelTitle  = serviceConfig.model.title,
                        moduleName  = serviceConfig.model.moduleName,
                        moduleTitle = serviceConfig.model.moduleTitle,
                        rules       = list3
                    });
                }
            }
            List <core_fieldRightsRule> lstRule = dbContext.Fetch <core_fieldRightsRule>("where RuleEnabled = 1", new object[0]);
            List <string> list7 = lstRule.Select(r => r.ModelName).Distinct().ToList();

            foreach (string item4 in list7)
            {
                ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(item4);
                if (serviceConfig != null)
                {
                    List <core_fieldRightsRule> list8 = (from a in lstRule
                                                         where a.ModelName == item4
                                                         select a).ToList();
                    List <object> list3 = new List <object>();
                    foreach (core_fieldRightsRule item5 in list8)
                    {
                        if (item5 != null)
                        {
                            list3.Add(new
                            {
                                id   = item5.ID,
                                text = item5.Title
                            });
                        }
                    }
                    rightsModel.fieldRights.Add(new RightsDataModel
                    {
                        modelName   = serviceConfig.model.name,
                        modelTitle  = serviceConfig.model.title,
                        moduleName  = serviceConfig.model.moduleName,
                        moduleTitle = serviceConfig.model.moduleTitle,
                        rules       = list3
                    });
                }
            }
            core_right core_rights = dbContext.FirstOrDefault <core_right>("where MasterType = @0 and MasterID = @1", new object[2]
            {
                "role",
                masterId
            });

            if (core_rights != null && !string.IsNullOrEmpty(core_rights.RightsValue))
            {
                RightsSaveModel rightsSaveModel = JsonHelper.DeserializeJsonToObject <RightsSaveModel>(core_rights.RightsValue);
                if (rightsSaveModel != null)
                {
                    rightsModel.menuRights = rightsSaveModel.menuRights;
                    using (List <RightsDataSaveModel> .Enumerator enumerator5 = rightsSaveModel.funRights.GetEnumerator())
                    {
                        while (enumerator5.MoveNext())
                        {
                            Func <RightsDataModel, bool> func      = null;
                            RightsDataSaveModel          value     = enumerator5.Current;
                            List <RightsDataModel>       funRights = rightsModel.funRights;
                            func = ((RightsDataModel a) => a.modelName == value.modelName);
                            RightsDataModel rightsDataModel = funRights.FirstOrDefault(func);
                            if (rightsDataModel != null)
                            {
                                rightsDataModel.rightsValue = value.rightsValue;
                            }
                        }
                    }
                    using (List <RightsDataSaveModel> .Enumerator enumerator5 = rightsSaveModel.dataRights.GetEnumerator())
                    {
                        while (enumerator5.MoveNext())
                        {
                            Func <RightsDataModel, bool> func2      = null;
                            RightsDataSaveModel          value2     = enumerator5.Current;
                            List <RightsDataModel>       dataRights = rightsModel.dataRights;
                            func2 = ((RightsDataModel a) => a.modelName == value2.modelName);
                            RightsDataModel rightsDataModel2 = dataRights.FirstOrDefault(func2);
                            if (rightsDataModel2 != null)
                            {
                                rightsDataModel2.rightsValue = value2.rightsValue;
                            }
                        }
                    }
                    using (List <RightsDataSaveModel> .Enumerator enumerator5 = rightsSaveModel.fieldRights.GetEnumerator())
                    {
                        while (enumerator5.MoveNext())
                        {
                            Func <RightsDataModel, bool> func3       = null;
                            RightsDataSaveModel          value3      = enumerator5.Current;
                            List <RightsDataModel>       fieldRights = rightsModel.fieldRights;
                            func3 = ((RightsDataModel a) => a.modelName == value3.modelName);
                            RightsDataModel rightsDataModel = fieldRights.FirstOrDefault(func3);
                            if (rightsDataModel != null)
                            {
                                rightsDataModel.rightsValue = value3.rightsValue;
                            }
                        }
                    }
                }
            }
            return(rightsModel);
        }