Пример #1
0
        public ActionResult GetRoleAccess()
        {
            int roleid = DoRequest.GetFormInt("id");
            List <RoleAccessInfo> item = new List <RoleAccessInfo>();
            var resrole = QueryRoleAccess.Do(roleid);

            if (resrole != null && resrole.Body != null && resrole.Body.access_list != null)
            {
                item = resrole.Body.access_list;
                return(Json(new { error = false, role = item, message = "操作成功!" }));
            }

            return(Json(new { error = true, message = "操作失败" }));
        }
Пример #2
0
        public ActionResult PostRoleAccessData()
        {
            string xmlString = DoRequest.GetFormString("xml", false);

            xmlString = HttpUtility.UrlDecode(xmlString);
            int roleid = DoRequest.GetFormInt("id");

            string     ids    = "";
            int        _count = 0;
            List <int> idsi   = new List <int>();

            try
            {
                XmlDataDocument xmlDoc = new XmlDataDocument();
                xmlDoc.LoadXml(xmlString);
                XmlNodeList nodes = xmlDoc.SelectNodes("items/item");
                if (nodes != null)
                {
                    foreach (XmlNode item in nodes)
                    {
                        int access = Utils.StrToInt(item.Attributes["accessid"].Value.Trim(), 0);
                        int issel  = Utils.StrToInt(item.Attributes["isselect"].Value.Trim(), 0);
                        if (issel == 1)
                        {
                            if (_count == 0)
                            {
                                ids = access.ToString();
                            }
                            else
                            {
                                ids = ids + "," + access.ToString();
                            }
                            _count++;
                            idsi.Add(access);
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(Json(new { error = true, input = "message", message = "Xml解析失败..." }));
            }

            _count = 0;
            string delids = "";
            List <RoleAccessInfo> oldlist = new List <RoleAccessInfo>();
            var resrole = QueryRoleAccess.Do(roleid);

            if (resrole != null && resrole.Body != null && resrole.Body.access_list != null)
            {
                oldlist = resrole.Body.access_list;
            }
            foreach (RoleAccessInfo item in oldlist)
            {
                if (!idsi.Contains(item.access_id))
                {
                    if (_count == 0)
                    {
                        delids = item.access_id.ToString();
                    }
                    else
                    {
                        delids = delids + "," + item.access_id.ToString();
                    }
                    _count++;
                }
            }
            if (delids.Equals(""))
            {
                delids = "0";
            }

            var returnValue = -1;
            var res         = AddRoleAccess.Do(roleid, ids, delids);

            if (res != null && res.Header != null && res.Header.Result != null && res.Header.Result.Code != null)
            {
                returnValue = Utils.StrToInt(res.Header.Result.Code, -1);
            }
            if (returnValue == 0)
            {
                return(Json(new { error = false, message = "操作成功!" }));
            }

            return(Json(new { error = true, message = "操作失败!" }));
        }