public SortSuppliesViewModel(SuppliesSortState sortOrder) { IdProviderAscSort = sortOrder == SuppliesSortState.IdProviderAsc ? SuppliesSortState.IdProviderDesc : SuppliesSortState.IdProviderAsc; PriceAscSort = sortOrder == SuppliesSortState.PriceAsc ? SuppliesSortState.PriceDesc : SuppliesSortState.PriceAsc; DateSuppleAscSort = sortOrder == SuppliesSortState.DateSuppleAsc ? SuppliesSortState.DateSuppleDesc : SuppliesSortState.DateSuppleAsc; IdMaterialAscSort = sortOrder == SuppliesSortState.IdMaterialAsc ? SuppliesSortState.IdMaterialDesc : SuppliesSortState.IdMaterialAsc; Current = sortOrder; }
// GET: Materials public IActionResult Index(string datesupple, string startdate, string enddate, string namematerial, double?massmaterial, decimal?price, string surname, int page = 1, SuppliesSortState sortOrder = SuppliesSortState.DateSuppleAsc) { int pageSize = 10; IQueryable <Supplies> source = _context.Supplies.Include(s => s.IdMaterialNavigation).Include(s => s.IdProviderNavigation); if (datesupple != null) { source = source.Where(x => x.DateSupple == DateTime.Parse(datesupple)); } if (startdate != null && enddate != null) { source = source.Where(x => x.DateSupple >= DateTime.Parse(startdate) && x.DateSupple <= DateTime.Parse(enddate)); } if (namematerial != null) { source = source.Where(x => x.IdMaterialNavigation.NameMaterial == namematerial); } if (massmaterial != null && massmaterial != 0) { source = source.Where(x => x.IdMaterialNavigation.MassMaterial.Value == massmaterial.Value); } if (price != null && price != 0) { source = source.Where(x => x.Price.Value == price.Value); } if (surname != null) { source = source.Where(x => x.IdProviderNavigation.Surname == surname); } switch (sortOrder) { case SuppliesSortState.IdProviderAsc: source = source.OrderBy(x => x.IdProvider); break; case SuppliesSortState.IdProviderDesc: source = source.OrderByDescending(x => x.IdProvider); break; case SuppliesSortState.PriceAsc: source = source.OrderBy(x => x.Price); break; case SuppliesSortState.PriceDesc: source = source.OrderByDescending(x => x.Price); break; case SuppliesSortState.DateSuppleAsc: source = source.OrderBy(x => x.DateSupple); break; case SuppliesSortState.DateSuppleDesc: source = source.OrderByDescending(x => x.DateSupple); break; case SuppliesSortState.IdMaterialAsc: source = source.OrderBy(x => x.IdMaterial); break; case SuppliesSortState.IdMaterialDesc: source = source.OrderByDescending(x => x.IdMaterial); break; default: source = source.OrderBy(x => x.DateSupple); break; } var count = source.Count(); var items = source.Skip((page - 1) * pageSize).Take(pageSize); PageViewModel pageView = new PageViewModel(count, page, pageSize); SuppliesViewModel ivm = new SuppliesViewModel { PageViewModel = pageView, SortViewModel = new SortSuppliesViewModel(sortOrder), FilterViewModel = new FilterSuppliesViewModel(datesupple, startdate, enddate, namematerial, massmaterial, price, surname), Supplies = items }; return(View(ivm)); }