Beispiel #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="permissionItem"></param>
 public BusinessPermission(PermissionItem permissionItem)
 {
     this.PermissionKey = permissionItem.PermissionKey;
     this.PermissionItemGuid = permissionItem.PermissionItemGuid;
     this.PermissionItemValue = permissionItem.PermissionItemValue;
     this.CreateUserGuid = permissionItem.CreateUserGuid;
     this.CreateUserType = permissionItem.CreateUserType;
     this.IsFreeAwayCreator = permissionItem.IsFreeAwayCreator;
 }
        public ActionResult Data(string ownerGuid, ExecutorTypes ownerType)
        {
            NameValueCollection nvc = this.Request.Form;
            Dictionary<Guid, PermissionItem> changedPermissionItems = new Dictionary<Guid, PermissionItem>();
            //获取选中的radio值
            for (int i = 0; i < nvc.Count; i++)
            {
                string currentKey = nvc.AllKeys[i];
                string currentValue = nvc[i];

                if (currentKey.StartsWith(SystemConst.PermissionItemValuePrefix) && currentKey.EndsWith("||0"))
                {
                    string settingName = currentKey.Substring(0,currentKey.Length-1);

                    int guidStartPos = SystemConst.PermissionItemValuePrefix.Length;
                    int seperatorPos = currentKey.LastIndexOf(SystemConst.PermissionItemGuidValueSeperator);
                    int valueStarPos = seperatorPos + SystemConst.PermissionItemGuidValueSeperator.Length;
                    string settingKeyString = currentKey.Substring(guidStartPos, seperatorPos - guidStartPos);
                    Guid settingkeyGuid = new Guid(settingKeyString);
                    string settingValue = nvc[settingName];
                    if (string.IsNullOrWhiteSpace(settingValue) == false)
                    {
                        int permissionItemValue;
                        bool isSuccessful = int.TryParse(settingValue, out permissionItemValue);
                        if (isSuccessful == true)
                        {
                            //changedPermissionItems[settingKey] = permissionItemValue;
                            if (changedPermissionItems.ContainsKey(settingkeyGuid))
                            {
                                changedPermissionItems[settingkeyGuid].PermissionItemValue = permissionItemValue;
                            }
                            else
                            {
                                PermissionItem permissionItem =
                                    new PermissionItem(settingkeyGuid, permissionItemValue, BusinessUserBLL.CurrentUser.UserGuid, BusinessUserBLL.CurrentUser.UserType, Logics.False);
                                changedPermissionItems.Add(settingkeyGuid, permissionItem);
                            }
                        }
                    }
                }
            }

            foreach (var permissionItem in changedPermissionItems)
            {
                BusinessPermission currentItem = new BusinessPermission(permissionItem.Value);
                currentItem.OwnerKey = ownerGuid.ToString();
                currentItem.OwnerType = ownerType;
                currentItem.PermissionMode =  PermissionModes.Allow;
                currentItem.PermissionKind = PermissionKinds.Data;

                BusinessPermissionBLL.Instance.CreateOrUpdate(currentItem);
            }

            return Json(new LogicStatusInfo(true, "保存权限成功"));
        }
        public ActionResult Index(string ownerGuid, ExecutorTypes ownerType, PermissionModes permissionMode)
        {
            NameValueCollection nvc = this.Request.Form;
            Dictionary<Guid, PermissionItem> changedPermissionItems = new Dictionary<Guid, PermissionItem>();
            //获取选中的checkbox
            for (int i = 0; i < nvc.Count; i++)
            {
                string currentKey = nvc.AllKeys[i];
                string currentValue = nvc[i];

                if (currentKey.StartsWith(SystemConst.PermissionItemValuePrefix) && currentValue.ToLower() == "on")
                {
                    int guidStartPos = SystemConst.PermissionItemValuePrefix.Length;
                    int seperatorPos = currentKey.LastIndexOf(SystemConst.PermissionItemGuidValueSeperator);
                    int valueStarPos = seperatorPos + SystemConst.PermissionItemGuidValueSeperator.Length;
                    string permissionItemGuidString = currentKey.Substring(guidStartPos, seperatorPos - guidStartPos);
                    Guid permissionItemGuid = new Guid(permissionItemGuidString);
                    string permissionItemValueString = currentKey.Substring(valueStarPos);
                    int permissionItemValue = 0;
                    bool isSuccessful = int.TryParse(permissionItemValueString, out permissionItemValue);
                    if (isSuccessful == true)
                    {
                        if (changedPermissionItems.ContainsKey(permissionItemGuid))
                        {
                            changedPermissionItems[permissionItemGuid].PermissionItemValue |= permissionItemValue;
                        }
                        else
                        {
                            PermissionItem permissionItem =
                                new PermissionItem(permissionItemGuid, permissionItemValue, BusinessUserBLL.CurrentUser.UserGuid, BusinessUserBLL.CurrentUser.UserType, Logics.False);
                            changedPermissionItems.Add(permissionItemGuid, permissionItem);
                        }
                    }
                }
            }

            foreach ( var permissionItem in changedPermissionItems)
            {
                BusinessPermission currentItem = new BusinessPermission(permissionItem.Value);
                currentItem.OwnerKey = ownerGuid.ToString();
                currentItem.OwnerType = ownerType;
                currentItem.PermissionMode = permissionMode;
                currentItem.PermissionKind = PermissionKinds.Operating;

                BusinessPermissionBLL.Instance.CreateOrUpdate(currentItem);
            }

            return Json(new LogicStatusInfo(true, "保存权限成功"));
        }