Example #1
0
 public FilterViewModelBase(string category, PageSizeFilter pageSizeFilter, SortFilter sortFilter, ProducersFilter producersFilter, PageFilter pageFilter, GroupFilter groupFilter)
     : this(pageSizeFilter, sortFilter, pageFilter)
 {
     this.ProducersFilter = producersFilter;
     this.GroupsFilter = groupFilter;
     this.Filters.Add(producersFilter);
     this.Filters.Add(groupFilter);
     this.Category = category;
 }
Example #2
0
        public ActionResult Index(string category, PageSizeFilter pageSizeFilter, SortFilter sortFilter,
                                  ProducersFilter producerFilter, PageFilter pageFilter,
                                  [ModelBinder(typeof(GroupFilterBinder))] GroupFilter groupFilter)
        {
            try
            {
                var url = ProducerRedirect.GetUrl(Request.Url, category, producerFilter);
                if (url != string.Empty)
                {
                    return RedirectPermanent(url);
                }

                ViewModel = new FilterViewModelBase(category, pageSizeFilter, sortFilter, producerFilter, pageFilter,
                                                    groupFilter);

                var categoryObj = categoryRepository.Find(category);
                if (categoryObj == null)
                {
                    throw new Exception("Invalid category name.");
                }

                ViewModel.CategoryObj = categoryObj;
                IQueryable<Product> entities = productRepository.GetProductsWithProducerByProductName(category);
                entities = StartInitialize(entities);
                EndInitialize(entities);

                return View(ViewModel);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return RedirectToAction("index", "error", new { statusCode = 404 });
            }
        }
Example #3
0
        public static string GetUrl(Uri url, string category, ProducersFilter producersFilter)
        {
            var collection = HttpUtility.ParseQueryString(url.Query);
            var sb = new StringBuilder();
            if (!url.LocalPath.EndsWith("/"))
            {
                sb.Append('/');
                sb.Append(category);
                sb.Append('/');
            }
            var names = new List<string>();
            separator = ";";
            if (producersFilter.ParsedProducers.Any(o => o.Contains(separator)))
            {
                foreach (var item in producersFilter.ParsedProducers)
                {
                    if (item.Contains(separator))
                    {
                        names.AddRange(item.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries));
                    }
                    else
                    {
                        names.Add(item);
                    }
                }

                names = names.Select(o => o.ToLower()).Distinct().ToList();
            }
            else
            {
                if ((!url.ToString().Contains("producers")))
                {
                    return string.Empty;
                }
            }

            string[] productNames = names.ToArray();
            var pr = collection.Get("producers");
            if (pr != null)
            {
                productNames = pr.Split(new[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
            }

            sb.Append(string.Join("-", productNames));
            var isFirst = true;
            foreach (var item in collection.Keys)
            {
                var key = item.ToString();
                var value = collection.Get(key);
                if (key == "producers")
                {
                    continue;
                }
                if (isFirst)
                {
                    sb.Append('?');
                    isFirst = false;
                }
                else
                {
                    sb.Append('&');
                }

                sb.Append(key);
                sb.Append('=');
                sb.Append(value);
            }

            return sb.ToString().ToLower();
        }