Esempio n. 1
0
        private Object Edit_1(string parameters)
        {
            //刷新权限的定义
            ILimitLoader loader = LimitLoaderFactory.GetInstance();

            loader.Load();

            IDictionary <string, object> dic = ParameterHelper.ParseParameters(parameters);
            int id = Convert.ToInt32(dic["id"]);

            DBHelper db = new DBHelper();

            var model = db.First("select * from \"" + tablename + "\" where id=" + id);

            DataTable dt = db.QueryTable("select content->>'groupname' as groupname,jsonb_agg(jsonb_set(content,'{id}',id::text::jsonb)) as items from \"limit\" group by content->>'groupname'");

            Account account = new Account()
            {
                Id            = model.id,
                UserName      = model.content.Value <string>("username"),
                Name          = model.content.Value <string>("name"),
                ApplicationId = PluginContext.Current.Account.ApplicationId,
                Limit         = model.content["limit"] == null ? "" : model.content.Value <string>("limit")
            };

            var list = db.Where("select * from \"limit\"");
            Dictionary <int, bool> userlimits = new Dictionary <int, bool>();

            foreach (var item in list)
            {
                userlimits.Add(item.id, account.IsAllowed(item.id));
            }

            return(new { data = model, limits = dt, userlimit = userlimits });
        }
Esempio n. 2
0
        public Object Edit(string parameters)
        {
            //刷新权限的定义
            ILimitLoader loader = LimitLoaderFactory.GetInstance();

            loader.Load();

            IDictionary <string, object> dic = ParameterHelper.ParseParameters(parameters);
            int id = Convert.ToInt32(dic["id"]);

            DBHelper db = new DBHelper(true);

            var     model   = db.First("select * from \"" + tablename + "\" where id=" + id);
            Account account = new Account()
            {
                Id            = model.id,
                UserName      = model.content.Value <string>("username"),
                Name          = model.content.Value <string>("name"),
                ApplicationId = PluginContext.Current.Account.ApplicationId,
                Limit         = model.content["limit"] == null ? "" : model.content.Value <string>("limit")
            };

            var list = db.Where("select * from \"limit\" order by id");
            Dictionary <int, bool> userlimits = new Dictionary <int, bool>();

            foreach (var item in list)
            {
                userlimits.Add(item.id, account.IsAllowed(item.id));
            }

            var modules = (from c in list
                           group c by new { modulename = c.content.Value <string>("modulename"), modulesort = c.content.Value <int>("modulesort") } into g
                           select g.Key).OrderByDescending(c => c.modulesort).Select(c => c.modulename).ToList();
            Dictionary <string, List <string> > modulegroups = new Dictionary <string, List <string> >();

            foreach (string modulename in modules)
            {
                var sublist = list.Where(c => c.content.Value <string>("modulename") == modulename);
                var groups  = (from c in sublist
                               group c by new { groupname = c.content.Value <string>("groupname"), groupsort = c.content.Value <int>("groupsort") } into g
                               select g.Key).OrderByDescending(c => c.groupsort).Select(c => c.groupname).ToList();
                modulegroups.Add(modulename, groups);
            }

            list.ForEach(c => { c.content.Add("id", c.id); });
            List <JObject> limits = list.Select(c => c.content).ToList();

            return(new { data = model, modules = modules, modulegroups = modulegroups, limits = limits, userlimit = userlimits });
        }