Example #1
0
        public JsonResult SaveSysScopeAuthorize(string selectVillageIds)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(selectVillageIds))
                {
                    throw new MyException("获取选择的小区失败");
                }

                List <SysScopeAuthorize> scopeAuthorizes = new List <SysScopeAuthorize>();
                string[] strVillageIds = selectVillageIds.Split(',');
                for (int i = 0; i < strVillageIds.Length; i++)
                {
                    string[] s = strVillageIds[i].Split('_');
                    if (s.Length != 2)
                    {
                        continue;
                    }
                    SysScopeAuthorize model = new SysScopeAuthorize();
                    model.ASID   = s[0];
                    model.ASDID  = GuidGenerator.GetGuid().ToString();
                    model.TagID  = s[1];
                    model.CPID   = GetCurrentUserCompanyId;
                    model.ASType = ASType.Village;
                    scopeAuthorizes.Add(model);
                }
                bool result = SysScopeAuthorizeServices.Add(scopeAuthorizes);
                if (!result)
                {
                    throw new MyException("授权失败");
                }

                CacheData.UpdateCacheUserLoginData(GetLoginUser.RecordID);
                return(Json(MyResult.Success()));
            }
            catch (MyException ex)
            {
                return(Json(MyResult.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "作用域授权失败");
                return(Json(MyResult.Error("授权失败")));
            }
        }
Example #2
0
        public string GetSysScopeAuthorize()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Request.Params["scopeId"]))
                {
                    return(string.Empty);
                }

                string scopeId = Request.Params["scopeId"];

                SysScope scope = SysScopeServices.QuerySysScopeByRecordId(scopeId);
                if (scope == null)
                {
                    return(string.Empty);
                }

                StringBuilder strTree = new StringBuilder();
                strTree.Append("[{\"id\":\"" + scope.ASID + "\",");
                strTree.Append("\"attributes\":{\"type\":0},");
                strTree.Append("\"text\":\"" + scope.ASName + "[作用域]\"");

                List <SysScopeAuthorize> scopeAuthorizes = SysScopeAuthorizeServices.QuerySysScopeAuthorizeByScopeId(scope.ASID)
                                                           .Where(p => p.ASType == ASType.Village).ToList();

                List <BaseCompany> compamys = CompanyServices.QueryCompanyAndSubordinateCompany(GetCurrentUserCompanyId);
                if (compamys.Count == 0)
                {
                    return(string.Empty);
                }

                var list = VillageServices.QueryVillageByCompanyIds(compamys.Select(p => p.CPID).ToList());
                if (list.Count > 0)
                {
                    strTree.Append(",\"children\":[");
                }

                int i = 1;
                foreach (var item in list)
                {
                    string      villageName = item.VName;
                    BaseCompany company     = compamys.FirstOrDefault(p => p.CPID == item.CPID);
                    if (company != null)
                    {
                        villageName = string.Format("{0}【{1}】", item.VName, company.CPName);
                    }
                    strTree.Append("{\"id\":\"" + scope.ASID + "_" + item.VID + "\",");
                    strTree.Append("\"attributes\":{\"type\":1},");
                    strTree.Append("\"text\":\"" + villageName + "\"");
                    if (scopeAuthorizes != null && scopeAuthorizes.Exists(p => p.TagID == item.VID))
                    {
                        strTree.Append(",\"checked\":true");
                    }

                    strTree.Append("}");
                    if (i != list.Count())
                    {
                        strTree.Append(",");
                    }
                    i++;
                }
                if (list.Count > 0)
                {
                    strTree.Append("]");
                }

                strTree.Append("}]");
                return(strTree.ToString());
            }
            catch (MyException ex)
            {
                return(string.Empty);
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "作用域授权时获取小区信息失败");
                return(string.Empty);
            }
        }