public ActionResult ComponentsCatalog(string[] Brands, string returnUrl, CommonSort SortByIncreaseName = CommonSort.Нет, CommonSort SortByIncreasePrice = CommonSort.Нет, CommonSort SortByIncreaseProducedAt = CommonSort.Нет, string category = "Процессоры", int?minPrice = null, int?maxPrice = null, int page = 1, int pageSize = 20)
        {
            ViewBag.returnUrl = returnUrl;

            if (Session["CurrentFilter"] == null || ((PcComponentsFilter)Session["CurrentFilter"]).Category != category)
            {
                Session["CurrentFilter"] = new PcComponentsFilter();
            }

            PcComponentsFilter curFilter = new PcComponentsFilter {
                SortByIncreaseName = SortByIncreaseName, SortByIncreasePrice = SortByIncreasePrice, SortByIncreaseProducedAt = SortByIncreaseProducedAt, MinPrice = minPrice, MaxPrice = maxPrice, Brands = Brands, Category = category
            };

            if (curFilter.ValidateInputParameters())
            {
                Session["CurrentFilter"] = curFilter;
            }
            else
            {
                ModelState.AddModelError("CatalogViewModel", curFilter.ErrorMessage);
            }

            IEnumerable <Good> allGoods = componentsUnit.GetGoodsDependsOnCategory(category);

            IEnumerable <Good> filteredGoods = componentsUnit.GetGoodsDependsOnFilter(category, (PcComponentsFilter)Session["CurrentFilter"]);

            if (allGoods != null && filteredGoods != null)
            {
                return(View(CatalogViewModel <Good> .GetCatalogViewModel(page, pageSize, filteredGoods, allGoods, category)));
            }
            throw new HttpException(404, "Page Not Found");
        }
Example #2
0
 private static T QuickSelectList <T>(List <T> source, int begin, int end, int index, SelectType type, Func <T, T, bool> comparer)
 {
     if (end - begin + 1 >= index)
     {
         int partition = 0;
         if (type == SelectType.HEADER)
         {
             partition = CommonSort.Partition(source, begin, end, begin, comparer);
         }
         else if (type == SelectType.END)
         {
             partition = CommonSort.Partition(source, begin, end, end, comparer);
         }
         else
         {
             partition = CommonSort.Partition(source, begin, end, (begin + end) / 2, comparer);
         }
         if (index + begin < partition)
         {
             QuickSelectList(source, begin, partition, index, type, comparer);
         }
         else if (index + begin > partition)
         {
             QuickSelectList(source, partition + 1, end, index - partition + begin - 1, type, comparer);
         }
         else
         {
             return(source[partition]);
         }
     }
     throw new IndexOutOfRangeException();
 }
Example #3
0
        public void HeapSort_asc_true()
        {
            List <int> listData = new List <int>()
            {
                5, 8, 0, 4, 2, 7, 6, 1, 9, 3
            };

            CommonSort.HeapSort(listData);
            listData.RemoveAt(0);
            Assert.IsTrue(Compare(listData.ToArray(), rightData));
        }
Example #4
0
 private static T QuickSelectList <T>(List <T> source, int begin, int end, int index, Func <T, T, bool> comparer)
 {
     if (end - begin + 1 >= index)
     {
         int partition = CommonSort.RandomPartition(source, begin, end, comparer);
         if (index + begin < partition)
         {
             QuickSelectList(source, begin, partition, index, comparer);
         }
         else if (index + begin > partition)
         {
             QuickSelectList(source, partition + 1, end, index - partition + begin - 1, comparer);
         }
         else
         {
             return(source[partition]);
         }
     }
     throw new IndexOutOfRangeException();
 }
Example #5
0
 public void QuickSort_asc_true()
 {
     CommonSort.QuickSort(data);
     Assert.IsTrue(Compare(data, rightData));
 }
Example #6
0
 public void MergeSort_asc_true()
 {
     CommonSort.MergeSort(data);
     Assert.IsTrue(Compare(data, rightData));
 }
Example #7
0
 public void ShellSort_asc_true()
 {
     CommonSort.ShellSort(data);
     Assert.IsTrue(Compare(data, rightData));
 }
Example #8
0
 public void BinaryInsertionSort_asc_true()
 {
     CommonSort.BinaryInsertionSort(data);
     Assert.IsTrue(Compare(data, rightData));
 }