Ejemplo n.º 1
0
		public Contract_GroupFilter ToContract(ISession session)
		{
			Contract_GroupFilter contract = new Contract_GroupFilter();
			contract.GroupFilterID = this.GroupFilterID;
			contract.GroupFilterName = this.GroupFilterName;
			contract.ApplyToSeries = this.ApplyToSeries;
			contract.BaseCondition = this.BaseCondition;
			contract.SortingCriteria = this.SortingCriteria;
			contract.Locked = this.Locked;

			contract.FilterConditions = new List<Contract_GroupFilterCondition>();
			foreach (GroupFilterCondition gfc in GetFilterConditions(session))
				contract.FilterConditions.Add(gfc.ToContract());

			return contract;
		}
Ejemplo n.º 2
0
 public static GroupFilter FromContract(Contract_GroupFilter gfc)
 {
     GroupFilter gf = new GroupFilter();
     gf.GroupFilterID = gfc.GroupFilterID ?? 0;
     gf.GroupFilterName = gfc.GroupFilterName;
     gf.ApplyToSeries = gfc.ApplyToSeries;
     gf.BaseCondition = gfc.BaseCondition;
     gf.SortingCriteria = gfc.SortingCriteria;
     gf.Locked = gfc.Locked;
     gf.InvisibleInClients = gfc.InvisibleInClients;
     gf.ParentGroupFilterID = gfc.ParentGroupFilterID;
     gf.FilterType = gfc.FilterType;
     List<GroupFilterCondition> conds = new List<GroupFilterCondition>();
     foreach (Contract_GroupFilterCondition c in gfc.FilterConditions)
     {
         GroupFilterCondition cc = new GroupFilterCondition();
         cc.ConditionType = c.ConditionType;
         cc.ConditionOperator = c.ConditionOperator;
         cc.ConditionParameter = c.ConditionParameter;
         conds.Add(cc);
     }
     gf.Conditions = conds;
     gf.GroupsIds = gfc.Groups ?? new Dictionary<int, HashSet<int>>();
     gf.SeriesIds = gfc.Series ?? new Dictionary<int, HashSet<int>>();
     return gf;
 }
Ejemplo n.º 3
0
 public static Contract_GroupFilter EvaluateContract(Contract_GroupFilter gfc)
 {
     GroupFilter gf = FromContract(gfc);
     gf.EvaluateAnimeGroups();
     gf.EvaluateAnimeSeries();
     return gf.ToContract();
 }
Ejemplo n.º 4
0
 public Contract_GroupFilter ToContract(ISession session)
 {
     Contract_GroupFilter contract = new Contract_GroupFilter();
     contract.GroupFilterID = this.GroupFilterID;
     contract.GroupFilterName = this.GroupFilterName;
     contract.ApplyToSeries = this.ApplyToSeries;
     contract.BaseCondition = this.BaseCondition;
     contract.SortingCriteria = this.SortingCriteria;
     contract.Locked = this.Locked;
     contract.FilterType = this.FilterType;
     contract.ParentGroupFilterID = this.ParentGroupFilterID;
     contract.InvisibleInClients = this.InvisibleInClients;
     contract.FilterConditions = new List<Contract_GroupFilterCondition>();
     foreach (GroupFilterCondition gfc in Conditions)
         contract.FilterConditions.Add(gfc.ToContract());
     contract.Groups = this.GroupsIds;
     contract.Series = this.SeriesIds;
     contract.Childs = GroupFilterID==0 ? new HashSet<int>() : RepoFactory.GroupFilter.GetByParentID(GroupFilterID).Select(a => a.GroupFilterID).ToHashSet();
     return contract;
 }
Ejemplo n.º 5
0
        public Contract_GroupFilter_SaveResponse SaveGroupFilter(Contract_GroupFilter contract)
        {
            Contract_GroupFilter_SaveResponse response = new Contract_GroupFilter_SaveResponse();
            response.ErrorMessage = string.Empty;
            response.GroupFilter = null;

            GroupFilterRepository repGF = new GroupFilterRepository();
            GroupFilterConditionRepository repGFC = new GroupFilterConditionRepository();

            // Process the group
            GroupFilter gf = null;
            if (contract.GroupFilterID.HasValue)
            {
                gf = repGF.GetByID(contract.GroupFilterID.Value);
                if (gf == null)
                {
                    response.ErrorMessage = "Could not find existing Group Filter with ID: " + contract.GroupFilterID.Value.ToString();
                    return response;
                }
            }
            else
                gf = new GroupFilter();

            gf.GroupFilterName = contract.GroupFilterName;
            gf.ApplyToSeries = contract.ApplyToSeries;
            gf.BaseCondition = contract.BaseCondition;
            gf.SortingCriteria = contract.SortingCriteria;

            if (string.IsNullOrEmpty(gf.GroupFilterName))
            {
                response.ErrorMessage = "Must specify a group filter name";
                return response;
            }

            repGF.Save(gf);

            // Process the filter conditions

            // check for any that have been deleted
            foreach (GroupFilterCondition gfc in gf.FilterConditions)
            {
                bool gfcExists = false;
                foreach (Contract_GroupFilterCondition gfc_con in contract.FilterConditions)
                {
                    if (gfc_con.GroupFilterConditionID.HasValue && gfc_con.GroupFilterConditionID.Value == gfc.GroupFilterConditionID)
                    {
                        gfcExists = true;
                        break;
                    }
                }
                if (!gfcExists)
                    repGFC.Delete(gfc.GroupFilterConditionID);
            }

            // save newly added or modified ones
            foreach (Contract_GroupFilterCondition gfc_con in contract.FilterConditions)
            {
                GroupFilterCondition gfc = null;
                if (gfc_con.GroupFilterConditionID.HasValue)
                {
                    gfc = repGFC.GetByID(gfc_con.GroupFilterConditionID.Value);
                    if (gfc == null)
                    {
                        response.ErrorMessage = "Could not find existing Group Filter Condition with ID: " + gfc_con.GroupFilterConditionID.ToString();
                        return response;
                    }
                }
                else
                    gfc = new GroupFilterCondition();

                gfc.ConditionOperator = gfc_con.ConditionOperator;
                gfc.ConditionParameter = gfc_con.ConditionParameter;
                gfc.ConditionType = gfc_con.ConditionType;
                gfc.GroupFilterID = gf.GroupFilterID;

                repGFC.Save(gfc);
            }

            response.GroupFilter = gf.ToContract();

            return response;
        }
        public Contract_GroupFilter_SaveResponse SaveGroupFilter(Contract_GroupFilter contract)
        {
            Contract_GroupFilter_SaveResponse response = new Contract_GroupFilter_SaveResponse();
            response.ErrorMessage = string.Empty;
            response.GroupFilter = null;

            // Process the group
            GroupFilter gf;
            if (contract.GroupFilterID.HasValue && contract.GroupFilterID.Value!=0)
            {
                gf = RepoFactory.GroupFilter.GetByID(contract.GroupFilterID.Value);
                if (gf == null)
                {
                    response.ErrorMessage = "Could not find existing Group Filter with ID: " +
                                            contract.GroupFilterID.Value.ToString();
                    return response;
                }
            }
            gf = GroupFilter.FromContract(contract);
            gf.EvaluateAnimeGroups();
            gf.EvaluateAnimeSeries();
            RepoFactory.GroupFilter.Save(gf);
            response.GroupFilter = gf.ToContract();
            return response;
        }
 public Contract_GroupFilter EvaluateGroupFilter(Contract_GroupFilter contract)
 {
     try
     {
         return GroupFilter.EvaluateContract(contract);
     }
     catch (Exception ex)
     {
         logger.Error( ex,ex.ToString());
         return new Contract_GroupFilter();
     }
 }