Пример #1
0
        public static Operation GetOperation(string appKey, string targetCode, string operationCode)
        {
            App    app    = App.GetApp(appKey);
            Target target = Target.GetTarget(appKey, targetCode);

            if (app == null || target == null)
            {
                return(null);
            }
            return(OperationInfoRepo.Read()
                   .FirstOrDefault(op => op.AppId == app.Id &&
                                   op.TargetId == target.Id &&
                                   op.Code == operationCode)
                   .MappingTo <Operation>());
        }
Пример #2
0
        /// <summary>
        /// 导入权限清单
        /// </summary>
        /// <param name="targetPettyList">清单对象列表</param>
        public void ImportManifest(List <TargetPetty> targetPettyList)
        {
            lock (ImportLocker)
            {
                //清除数据库中有且清单中没有的 Target
                List <Target> targetList = this.TargetList;
                if (targetList != null)
                {
                    foreach (Target target in targetList)
                    {
                        if (!targetPettyList.Exists(tag => tag.Code == target.Code))
                        {
                            target.Delete();//会级联清除 Operation
                        }
                    }
                }
                //更新或添加清单中的 Target
                foreach (TargetPetty targetPetty in targetPettyList)
                {
                    //保存或更新 Target
                    Target target = Target.GetTarget(this.Key, targetPetty.Code) ?? new Target();
                    Mapper.Clone <TargetPetty, Target>(targetPetty, ref target, new List <string> {
                        "OperationList", "Id", "AppKey"
                    });
                    target.AppId = this.Id;
                    target.Sort  = targetPettyList.Count() - 1 - targetPettyList.IndexOf(targetPetty);
                    target.Save();

                    #region 处理单个 Target 下的 Operation
                    //清除数据库中有且清单中没有的 Operation
                    List <Operation> operationList = target.OperationList;
                    if (operationList != null)
                    {
                        foreach (Operation operation in operationList)
                        {
                            if (!targetPetty.OperationList.Exists(op => op.Code == operation.Code))
                            {
                                operation.AppId    = this.Id;
                                operation.TargetId = target.Id;
                                operation.Delete();
                            }
                        }
                    }
                    //更新或添加清单中的 Operation
                    if (targetPetty.OperationList != null)
                    {
                        foreach (OperationPetty operationPetty in targetPetty.OperationList)
                        {
                            Operation operation = Operation.GetOperation(this.Key,
                                                                         targetPetty.Code,
                                                                         operationPetty.Code)
                                                  ?? new Operation();
                            Mapper.Clone <OperationPetty, Operation>(operationPetty, ref operation, new List <string> {
                                "Id", "AppKey", "TargetCode"
                            });
                            operation.AppId    = this.Id;
                            operation.TargetId = target.Id;
                            operation.Save();
                        }
                    }
                    #endregion
                }
            }
        }