/// <summary> /// Insert the new filter to the collection (+ DB) /// </summary> public FilterSet SaveNewFilter(FilterSet newFilter) { dbEntities.InsertNewFilter(newFilter); dbEntities.SaveAllChanges(); filters.Add(newFilter); return(dbEntities.GetAllFilters(eventId).OrderBy(f => f.ID_Filter).Last()); }
/// <summary> /// Determine if the given user match the defined filters/rules. /// If that's the case, the UI should display the define color. /// /// Comparison can be currently done on : double, string. /// You can then compare with the name, the company name, the age... /// The following ones could be added in a future version : bool, datetime /// </summary> /// <returns>Returns the hexadecimal code, null if there is no filter that match.</returns> public string DetermineColorForCard(List <EventFieldUserSet> currentUser) { string hexaDecimalToReturn = null; for (int i = 0; i < currentUser.Count; i++) { string fieldName = currentUser[i].EventFieldSet.FieldSet.Name; string fieldValue = currentUser[i].Value; // Determine the type (numbers and characters are take over) Regex numbersRegex = new Regex(@"^[0-9]+$", RegexOptions.Compiled | RegexOptions.IgnoreCase); if (numbersRegex.IsMatch(fieldValue)) { // Type = NUMBERS List <FilterSet> relevantFilters = _dbEntities.GetAllFilters(IdEvent) .Where(f => FiltersHelper.LogicalOperatorsForNumbers.Contains(f.LogicalOperator) && f.EventFieldSet.FieldSet.Name.Equals(fieldName)) .ToList(); foreach (FilterSet filter in relevantFilters) { if (FiltersHelper.Evaluate(Convert.ToDouble(fieldValue), Convert.ToDouble(filter.Value), filter.LogicalOperator)) { // There is a MATCH - check if a rule is defined for "Window" target return(RetrieveWindowColor(filter.ID_Filter)); } } } else { // Type = CHARACTERS List <FilterSet> relevantFilters = _dbEntities.GetAllFilters(IdEvent) .Where(f => FiltersHelper.LogicalOperatorsForCharacters.Contains(f.LogicalOperator) && f.EventFieldSet.FieldSet.Name.Equals(fieldName)) .ToList(); foreach (FilterSet filter in relevantFilters) { if (FiltersHelper.Evaluate(fieldValue, filter.Value, filter.LogicalOperator)) { // There is a MATCH - check if a rule is defined for "Window" target return(RetrieveWindowColor(filter.ID_Filter)); } } } } return(hexaDecimalToReturn); }