public Response Execute(string request)
        {
            var req = JsonConvert.DeserializeObject <Request <LimitRole> >(request);
            var obj = req.Filter;

            var sqlStr = @"SELECT b.Id,b.Name,b.IsDefault FROM LimitRole AS b ";
            var cmd    = CommandHelper.CreateText <LimitRole>(FetchType.Fetch, sqlStr);
            //cmd.Params.Add("@userid", obj.UserId);
            var response = DbContext.GetInstance().Execute(cmd);

            if (response.Entities != null)
            {
                foreach (LimitRole item in response.Entities)
                {
                    if (LimitHelper.IsChecked(obj.UserId, item.Id))
                    {
                        item.IsChecked = true;
                    }
                    else
                    {
                        item.IsChecked = false;
                    }
                }
            }

            return(response);
        }
Exemple #2
0
        public Response Execute(string request)
        {
            var    req     = JsonConvert.DeserializeObject <Request <Limit> >(request);
            var    objList = req.Entities;
            int    type    = 0;//权限动作类型  1操作,2查看,3特殊
            string roleid  = string.Empty;

            if (objList.Count > 0)
            {
                Limit limit = objList[0];
                type   = limit.Type;
                roleid = limit.RoleId;
                if (limit.RoleId.Equals("000002")) //假如是默认角色,不能更改权限 || limit.RoleId.Equals("000001")
                {
                    return(ResultHelper.Fail("默认角色不能修改权限"));
                }
            }
            else
            {
                return(ResultHelper.Fail("权限数据为空"));
            }
            DeleteLimitByRole(roleid, type);//删除对应角色及动作的权限
            foreach (Limit item in objList)
            {
                item.SetNewEntity();
                //Limit limit = GetOwnLimit(item.RoleId, item.LimitName);
                //if (limit == null)
                //{
                //    item.SetNewEntity();
                //}
                //else
                //{
                //    item.Id = limit.Id;
                //    item.RowState = RowState.Modified;
                //    item.SetCreateDate();
                //}
            }
            List <EntityBase> entity = new List <EntityBase>(objList);
            var cmd      = CommandHelper.CreateSave(entity);
            var response = DbContext.GetInstance().Execute(cmd);

            if (response.IsSuccess)
            {
                var list = LimitHelper.GetRoleUserMap(roleid);//获取对应角色的用户
                foreach (var item in list)
                {
                    LimitHelper.DeleteOnlieUser(item.UserId);//剔掉线
                }
            }
            return(response);
        }
        public Response Execute(string request)
        {
            var    req    = JsonConvert.DeserializeObject <Request <LimitRole> >(request);
            var    obj    = req.FirstEntity();
            string sqlStr = @"DELETE FROM LimitRoleUserMap WHERE UserId=@userid AND RoleId=@roleid";
            var    cmd1   = CommandHelper.CreateText <LimitRole>(FetchType.Execute, sqlStr);

            cmd1.Params.Add("@roleid", obj.Id);
            cmd1.Params.Add("@userid", obj.UserId);
            var response = DbContext.GetInstance().Execute(cmd1);

            LimitHelper.DeleteOnlieUser(obj.UserId);//剔除对应在线用户
            return(response);
        }
Exemple #4
0
        public Response Execute(string request)
        {
            var req = JsonConvert.DeserializeObject <Request <LimitRole> >(request);
            var obj = req.FirstEntity();
            List <EntityBase> entites = new List <EntityBase>();

            if ((string.IsNullOrEmpty(obj.UserId) && !string.IsNullOrEmpty(obj.Id)))//从角色添加用户
            {
                foreach (var item in obj.MapList)
                {
                    if (!LimitHelper.IsChecked(item.UserId, item.RoleId))
                    {
                        item.SetNewEntity();
                        entites.Add(item);
                    }
                }
            }
            else//从用户添加角色
            {
                string delSql = @"DELETE FROM LimitRoleUserMap WHERE UserId=@Userid";
                var    cmd2   = CommandHelper.CreateText <LimitRoleUserMap>(FetchType.Execute, delSql);
                cmd2.Params.Add("@Userid", obj.UserId);
                DbContext.GetInstance().Execute(cmd2);
                foreach (var item in obj.MapList)
                {
                    item.SetNewEntity();
                    entites.Add(item);
                }
            }
            //保存用户角色关系
            var cmd      = CommandHelper.CreateSave(entites);
            var response = DbContext.GetInstance().Execute(cmd);

            if (response.IsSuccess)
            {                                                                            //角色更改,剔除相应的在线用户
                if ((string.IsNullOrEmpty(obj.UserId) && !string.IsNullOrEmpty(obj.Id))) //从角色添加用户
                {
                    foreach (LimitRoleUserMap item in entites)
                    {
                        var result = LimitHelper.DeleteOnlieUser(item.UserId);
                    }
                }
                else//从用户添加角色
                {
                    var result = LimitHelper.DeleteOnlieUser(obj.UserId);
                }
            }
            return(response);
        }
        /// <summary>
        /// 获取用户权限
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static List <Limit> GetLimitList(string userid)
        {
            List <Limit> list = new List <Limit>();
            Dictionary <string, HashSet <int> > dic = LimitHelper.GetLimitByUser(userid);

            foreach (var item in dic)
            {
                Limit limit = new Limit();
                int   rang  = 0;
                foreach (int k in item.Value)
                {
                    rang += k;
                }
                limit.LimitName   = item.Key;
                limit.LimitDetail = rang;
                list.Add(limit);
            }
            return(list);
        }
        public Response Execute(User currentUser, string request)
        {
            var req = JsonConvert.DeserializeObject <Request <LimitFilter> >(request);
            var obj = req.Filter;
            Dictionary <string, HashSet <int> > dic = LimitHelper.GetLimitByUser(currentUser.Id, obj.LimitName);
            Response res = ResultHelper.CreateResponse();

            foreach (var item in dic)
            {
                Limit limit = new Limit();
                int   rang  = 0;
                foreach (int k in item.Value)
                {
                    rang += k;
                }
                limit.LimitName   = item.Key;
                limit.LimitDetail = rang;
                res.Entities.Add(limit);
            }
            return(res);
        }
Exemple #7
0
        public Response Execute(string request)
        {
            var req = JsonConvert.DeserializeObject <Request <LimitModelFilter> >(request);
            var obj = req.Filter;
            List <LimitBaseData> list = LimitName.LimitList;
            Response             res  = ResultHelper.Success();

            //foreach (var item in list)
            //{
            //    if (item.Type == obj.Type)
            //    {
            //        res.Entities.Add(item);
            //    }
            //}
            //var ownLimit = GetOwnLimit(obj.RoleId, obj.Type);
            //if (ownLimit != null && ownLimit.Count > 0)
            //{
            //    List<LimitBaseData> OwnLimitList = new List<LimitBaseData>();
            //    foreach (var item in ownLimit)
            //    {
            //        LimitBaseData data = new LimitBaseData { Range = (item as Limit).LimitDetail, NameId = (item as Limit).LimitName };
            //        OwnLimitList.Add(data);
            //    }
            //    res.Tag = OwnLimitList;
            //}

            //获取所有列表
            foreach (var item in list)
            {
                if (item.Type == obj.Type)
                {
                    res.Entities.Add(item);
                }
            }
            var ownLimitList = GetOwnLimit(obj.RoleId, obj.Type);//获取拥有的权限列表

            foreach (var item in res.Entities)
            {
                if ((item as LimitBaseData).Type != 1)//针对权限值只有0或1的情况
                {
                    (item as LimitBaseData).IsSelected = false;
                    (item as LimitBaseData).Range      = 0;
                }
                (item as LimitBaseData).DetailLimit = LimitHelper.GetLimitDetailList(item as LimitBaseData);
                foreach (var item1 in ownLimitList)
                {
                    if ((item as LimitBaseData).NameId == (item1 as Limit).LimitName)
                    {
                        if ((item as LimitBaseData).Type != 1)//针对权限值只有0或1的情况
                        {
                            (item as LimitBaseData).Range = (item1 as Limit).LimitDetail;
                            if ((item1 as Limit).LimitDetail == 1)
                            {
                                (item as LimitBaseData).IsSelected = true;
                            }
                            else
                            {
                                (item as LimitBaseData).IsSelected = false;
                            }
                        }

                        HashSet <int> rangeSet = new HashSet <int>();
                        LimitHelper.GetLimitRangeList((item1 as Limit).LimitDetail, rangeSet);

                        foreach (int k in rangeSet)
                        {
                            (item as LimitBaseData).DetailLimit.AsParallel().ForAll((j) =>
                            {
                                if (j.Range == k)
                                {
                                    j.IsSelected = true;
                                }
                            });
                        }
                    }
                }
            }

            return(res);
        }