private bool IsShortcut(FilterSql context, FilterCriteria itm, ref int index)
        {
            if (itm.Entity.IsCaseInsensitiveEqual(ShortcutPrice))
            {
                // TODO: where clause of special price not correct. product can appear in price and in special price range.

                if (itm.IsRange)
                {
                    string valueLeft, valueRight;
                    itm.Value.SplitToPair(out valueLeft, out valueRight, "~");

                    context.WhereClause.AppendFormat("((Price >= {0} And Price {1} {2}) Or (SpecialPrice >= {0} And SpecialPrice {1} {2} And SpecialPriceStartDateTimeUtc <= {3} And SpecialPriceEndDateTimeUtc >= {3}))",
                                                     FormatParameterIndex(ref index),
                                                     itm.Operator == FilterOperator.RangeGreaterEqualLessEqual ? "<=" : "<",
                                                     FormatParameterIndex(ref index),
                                                     FormatParameterIndex(ref index)
                                                     );

                    context.Values.Add(FilterValueToObject(valueLeft, itm.Type ?? "Decimal"));
                    context.Values.Add(FilterValueToObject(valueRight, itm.Type ?? "Decimal"));
                    context.Values.Add(DateTime.UtcNow);
                }
                else
                {
                    context.WhereClause.AppendFormat("(Price {0} {1} Or (SpecialPrice {0} {1} And SpecialPriceStartDateTimeUtc <= {2} And SpecialPriceEndDateTimeUtc >= {2}))",
                                                     itm.Operator == null ? "=" : itm.Operator.ToString(),
                                                     FormatParameterIndex(ref index),
                                                     FormatParameterIndex(ref index));

                    context.Values.Add(FilterValueToObject(itm.Value, itm.Type ?? "Decimal"));
                    context.Values.Add(DateTime.UtcNow);
                }
            }
            else if (itm.Entity.IsCaseInsensitiveEqual(ShortcutSpecAttribute))
            {
                context.WhereClause.AppendFormat("SpecificationAttributeOptionId {0} {1}", itm.Operator == null ? "=" : itm.Operator.ToString(), FormatParameterIndex(ref index));

                context.Values.Add(itm.ID ?? 0);
            }
            else
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        public static string GetUrl(this FilterProductContext context, FilterCriteria criteriaAdd = null, FilterCriteria criteriaRemove = null)
        {
            var url = "{0}?pagesize={1}&viewmode={2}".FormatInvariant(context.Path, context.PageSize, context.ViewMode);

            if (context.OrderBy.HasValue)
            {
                url = "{0}&orderby={1}".FormatInvariant(url, context.OrderBy.Value);
            }

            try
            {
                if (criteriaAdd != null || criteriaRemove != null)
                {
                    var criterias = new List <FilterCriteria>();

                    if (context.Criteria != null && context.Criteria.Count > 0)
                    {
                        criterias.AddRange(context.Criteria.Where(c => !c.IsInactive));
                    }

                    if (criteriaAdd != null)
                    {
                        criterias.Add(criteriaAdd);
                    }
                    else
                    {
                        criterias.RemoveAll(c => c.Entity.IsCaseInsensitiveEqual(criteriaRemove.Entity) && c.Name.IsCaseInsensitiveEqual(criteriaRemove.Name) && c.Value.IsCaseInsensitiveEqual(criteriaRemove.Value));
                    }

                    if (criterias.Count > 0)
                    {
                        url = "{0}&filter={1}".FormatInvariant(url, HttpUtility.UrlEncode(JsonConvert.SerializeObject(criterias)));
                    }
                }
            }
            catch (Exception exc)
            {
                exc.Dump();
            }

            return(url);
        }
Example #3
0
        public static string ToDescription(this FilterCriteria criteria)
        {
            var localize = EngineContext.Current.Resolve <ILocalizationService>();

            if (criteria == null || criteria.Value.IsEmpty())
            {
                return(localize.GetResource("Common.Unspecified"));
            }

            if (criteria.Operator == FilterOperator.RangeGreaterEqualLessEqual || criteria.Operator == FilterOperator.RangeGreaterEqualLess)
            {
                string valueLeft, valueRight;
                criteria.Value.SplitToPair(out valueLeft, out valueRight, "~");

                if (criteria.Entity.IsCaseInsensitiveEqual(FilterService.ShortcutPrice))
                {
                    return("{0} - {1}".FormatInvariant(FormatPrice(valueLeft), FormatPrice(valueRight)));
                }

                return("{0} - {1}".FormatInvariant(valueLeft, valueRight));
            }

            var value = (criteria.ValueLocalized.HasValue() ? criteria.ValueLocalized : criteria.Value);

            if (criteria.Entity.IsCaseInsensitiveEqual(FilterService.ShortcutPrice))
            {
                value = FormatPrice(criteria.Value);
            }

            if (criteria.Operator == FilterOperator.Unequal)
            {
                return("≠ {0}".FormatInvariant(value));
            }
            if (criteria.Operator == FilterOperator.Greater)
            {
                return("> {0}".FormatInvariant(value));
            }
            if (criteria.Operator == FilterOperator.GreaterEqual)
            {
                return("≥ {0}".FormatInvariant(value));
            }
            if (criteria.Operator == FilterOperator.Less)
            {
                return("< {0}".FormatInvariant(value));
            }
            if (criteria.Operator == FilterOperator.LessEqual)
            {
                return("≤ {0}".FormatInvariant(value));
            }
            if (criteria.Operator == FilterOperator.Contains)
            {
                return("{0} {1}".FormatInvariant(localize.GetResource("Products.Filter.Contains"), value));
            }
            if (criteria.Operator == FilterOperator.StartsWith)
            {
                return("{0} {1}".FormatInvariant(localize.GetResource("Products.Filter.StartsWith"), value));
            }
            if (criteria.Operator == FilterOperator.EndsWith)
            {
                return("{0} {1}".FormatInvariant(localize.GetResource("Products.Filter.EndsWith"), value));
            }

            return(value);
        }