public BuildStandartSortViewModel(BuildStandartSortState sortState) { PriceSort = sortState == BuildStandartSortState.PriceAsc ? BuildStandartSortState.PriceDes : BuildStandartSortState.PriceAsc; ComponentSort = sortState == BuildStandartSortState.ComponentTitleAsc ? BuildStandartSortState.ComponentTitleDes : BuildStandartSortState.ComponentTitleAsc; ServiceSort = sortState == BuildStandartSortState.ServiceTitleAsc ? BuildStandartSortState.ServiceTitleDes : BuildStandartSortState.ServiceTitleAsc; Current = sortState; }
public ViewResult List(int page = 1, decimal?maxPrice = decimal.MaxValue, decimal?minPrice = decimal.MinValue, int service = 0, int component = 0, BuildStandartSortState sortState = BuildStandartSortState.ComponentTitleAsc) { IEnumerable <BuildStandart> buildStandarts = _repository.Read(); if (maxPrice != null && maxPrice != decimal.MaxValue) { buildStandarts = buildStandarts.Where(x => x.Componet.Price + x.Service.Price < maxPrice); } if (service != 0) { buildStandarts = buildStandarts.Where(x => x.Service.Id == service); } if (component != 0) { buildStandarts = buildStandarts.Where(x => x.Componet.Id == component); } if (maxPrice != null && maxPrice != decimal.MinValue) { buildStandarts = buildStandarts.Where(x => x.Componet.Price + x.Service.Price > minPrice); } switch (sortState) { case BuildStandartSortState.ServiceTitleAsc: buildStandarts = buildStandarts.OrderBy(x => x.Service.Title); break; case BuildStandartSortState.PriceAsc: buildStandarts = buildStandarts.OrderBy(x => x.Service.Price + x.Componet.Price); break; case BuildStandartSortState.ServiceTitleDes: buildStandarts = buildStandarts.OrderByDescending(x => x.Service.Title); break; case BuildStandartSortState.PriceDes: buildStandarts = buildStandarts.OrderByDescending(x => x.Service.Price + x.Componet.Price); break; case BuildStandartSortState.ComponentTitleDes: buildStandarts = buildStandarts.OrderByDescending(x => x.Componet.Title); break; default: buildStandarts = buildStandarts.OrderBy(x => x.Componet.Title); break; } ; int count = buildStandarts.Count(); var Items = buildStandarts.Skip((page - 1) * pageSize).Take(pageSize).ToList(); BuilderStandartListViewModel res = new BuilderStandartListViewModel() { Standarts = Items, PageViewModel = new PageViewModel(count, page, pageSize), SortViewModel = new BuildStandartSortViewModel(sortState), FilterViewModel = new BuilderStabdartFilterViewModel(Items, component, service, minPrice, maxPrice) }; return(View(res)); }