Exemple #1
0
        public string GetPolicySetForLoginRest(PolicySetDataContract policySetFilter)
        {
            var queryResult = GetPolicySetForLogin(policySetFilter.LoginId.Value);

            try
            {
                var policyService = new PolicyService();

                foreach (var policySet in queryResult.SomeResult)
                {
                    var policyResult = policyService.GetPolicy(new PolicyDataContract {
                        PolicyId = policySet.PolicyId
                    });

                    if (!policyResult.BoolRes || policyResult.SomeResult == null || !policyResult.SomeResult.Any())
                    {
                        continue;
                    }

                    var policyInfo = policyResult.SomeResult[0];
                    policySet.PolicyName        = policyInfo.PolicyName;
                    policySet.PlatformId        = policyInfo.PlatformId;
                    policySet.PolicyInstruction = policyInfo.PolicyInstruction;
                    policySet.PolicyParam       = policySet.PolicyParam ?? policyInfo.PolicyDefaultParam;
                }
            }
            catch (Exception ex)
            {
                queryResult.ErrorRes = string.Concat("Не удалось получить дополнительную информацию о политике. ",
                                                     ex.Message);
            }

            return(JsonConvert.SerializeObject(queryResult));
        }
Exemple #2
0
        public Result <object> DeletePolicySet(PolicySetDataContract policySet)
        {
            var result = new Result <object>();

            try
            {
                if (policySet == null)
                {
                    throw new Exception("Hабор политик не задан");
                }

                using (var ctx = new PolicyProjectEntities())
                {
                    var delPolicySet = ctx.tbl_policy_set.FirstOrDefault(x => x.id == policySet.PolicySetId);
                    ctx.tbl_policy_set.Remove(delPolicySet);
                    result.BoolRes = ctx.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка удаления наборa политик. ", ex.Message);
            }

            return(result);
        }
Exemple #3
0
        public Result <object> AddPolicySet(PolicySetDataContract policySet)
        {
            var result = new Result <object>();

            try
            {
                if (policySet == null)
                {
                    throw new Exception("Новый набор политик не задан");
                }

                using (var ctx = new PolicyProjectEntities())
                {
                    policySet.PolicySetId = ctx.tbl_policy_set.Any() ? ctx.tbl_policy_set.Max(x => x.id) + 1 : 1;
                    var newPolicySet = PolicySetDataContract.FromPolicySetDataContractToTblPolicySet(policySet);
                    ctx.tbl_policy_set.Add(newPolicySet);
                    result.BoolRes = ctx.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка добавления набора политик. ", ex.Message);
            }

            return(result);
        }
Exemple #4
0
        public Result <PolicySetDataContract[]> GetPolicySet(PolicySetDataContract policySetFilter)
        {
            var result = new Result <PolicySetDataContract[]>();

            try
            {
                using (var ctx = new PolicyProjectEntities())
                {
                    if (policySetFilter == null)
                    {
                        result.SomeResult =
                            ctx.tbl_policy_set.Select(
                                policySetTblData => new PolicySetDataContract
                        {
                            PolicySetId = policySetTblData.id,
                            PolicyId    = policySetTblData.id_policy,
                            LoginId     = policySetTblData.id_login,
                            GroupId     = policySetTblData.id_group,
                            Selected    = policySetTblData.selected,
                            PolicyParam = policySetTblData.policy_param
                        })
                            .ToArray();
                    }
                    else
                    {
                        result.SomeResult =
                            ctx.tbl_policy_set.Where(
                                x => (policySetFilter.PolicyId > 0 && x.id_policy == policySetFilter.PolicyId) ||
                                (policySetFilter.LoginId > 0 && x.id_login == policySetFilter.LoginId) ||
                                (policySetFilter.GroupId > 0 && x.id_group == policySetFilter.GroupId))
                            .Select(
                                policySetTblData => new PolicySetDataContract
                        {
                            PolicySetId = policySetTblData.id,
                            PolicyId    = policySetTblData.id_policy,
                            LoginId     = policySetTblData.id_login,
                            GroupId     = policySetTblData.id_group,
                            Selected    = policySetTblData.selected,
                            PolicyParam = policySetTblData.policy_param
                        }).ToArray();
                    }

                    result.BoolRes = true;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка получения набора политик. ", ex.Message);
            }

            return(result);
        }
Exemple #5
0
        public static tbl_policy_set FromPolicySetDataContractToTblPolicySet(PolicySetDataContract policySetData)
        {
            if (policySetData.PolicySetId < 1 || policySetData.PolicyId < 1)
            {
                return(null);
            }

            return(new tbl_policy_set
            {
                id = policySetData.PolicySetId,
                id_group = policySetData.GroupId,
                id_policy = policySetData.PolicyId,
                id_login = policySetData.LoginId,
                selected = policySetData.Selected,
                policy_param = policySetData.PolicyParam
            });
        }
Exemple #6
0
        public static bool Compare(PolicySetDataContract obj1, PolicySetDataContract obj2)
        {
            if (obj1 == null && obj2 == null)
            {
                return(true);
            }

            if (obj1 == null && obj2 != null)
            {
                return(false);
            }

            if (obj1 != null && obj2 == null)
            {
                return(false);
            }

            return(obj1.PolicySetId == obj2.PolicySetId && obj1.PolicyId == obj2.PolicyId &&
                   obj1.LoginId == obj2.LoginId && obj1.GroupId == obj2.GroupId && obj1.PolicyParam == obj2.PolicyParam);
        }
Exemple #7
0
        public Result <object> UpdatePolicySet(PolicySetDataContract oldPolicySet, PolicySetDataContract newPolicySet)
        {
            var result = new Result <object>();

            try
            {
                if (oldPolicySet == null)
                {
                    throw new Exception("Текущий набор политик не задан");
                }

                if (newPolicySet == null)
                {
                    throw new Exception("Новый набор политик не задан");
                }

                using (var ctx = new PolicyProjectEntities())
                {
                    var selected = ctx.tbl_policy_set.FirstOrDefault(x => x.id == oldPolicySet.PolicySetId);

                    if (selected == null)
                    {
                        throw new Exception("Текущий набор политик не найден");
                    }

                    selected.id_policy    = newPolicySet.PolicyId;
                    selected.id_group     = newPolicySet.GroupId;
                    selected.id_login     = newPolicySet.LoginId;
                    selected.selected     = newPolicySet.Selected;
                    selected.policy_param = newPolicySet.PolicyParam;
                    result.BoolRes        = ctx.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка изменения наборa политик. ", ex.Message);
            }

            return(result);
        }
Exemple #8
0
        public string GetPolicySetRest(PolicySetDataContract policySetFilter)
        {
            var queryResult = GetPolicySet(policySetFilter);

            return(JsonConvert.SerializeObject(queryResult));
        }