Ejemplo n.º 1
0
        }                                             // текущее значение сортировки

        public SortViewModels(SortBuild sortBuild)
        {
            BuildNameSort = sortBuild == SortBuild.nameASC ? SortBuild.nameDSC : SortBuild.nameASC;
            ManufacSort   = sortBuild == SortBuild.manufacASC ? SortBuild.manufacDSC : SortBuild.manufacDSC;
            VolumSort     = sortBuild == SortBuild.voluemASC ? SortBuild.voluemDSC : SortBuild.voluemASC;
            ContractSort  = sortBuild == SortBuild.contracASC ? SortBuild.contracDSC : SortBuild.contracASC;
            Current       = sortBuild;
        }
Ejemplo n.º 2
0
        // GET: BuildingMaterials
        public async Task <IActionResult> Index(int?contr, string nameMaterial, SortBuild sortBuild = SortBuild.nameASC, int page = 1)
        {
            int pageSize = 10;
            IQueryable <BuildingMaterial> building = _context.BuildingMaterials.Include(b => b.ContractorIdNavigation)
                                                     .Include(b => b.ManufacturerIdNavigation);

            if (contr != null && contr != 0)
            {
                building = building.Where(p => p.ContractorId == contr);
            }
            if (!String.IsNullOrEmpty(nameMaterial))
            {
                building = building.Where(p => p.NameMaterial.Contains(nameMaterial));
            }


            switch (sortBuild)
            {
            case SortBuild.nameDSC:
                building = building.OrderByDescending(s => s.NameMaterial);
                break;

            case SortBuild.manufacDSC:
                building = building.OrderByDescending(s => s.ManufacturerIdNavigation.ManufacturerName);
                break;

            case SortBuild.manufacASC:
                building = building.OrderBy(s => s.ManufacturerIdNavigation.ManufacturerName);
                break;

            case SortBuild.voluemDSC:
                building = building.OrderByDescending(s => s.VolumePurchaseQuantity);
                break;

            case SortBuild.voluemASC:
                building = building.OrderBy(s => s.VolumePurchaseQuantity);
                break;

            case SortBuild.contracDSC:
                building = building.OrderByDescending(s => s.ContractorIdNavigation.NameCompany);
                break;

            case SortBuild.contracASC:
                building = building.OrderBy(s => s.ContractorIdNavigation.NameCompany);
                break;

            default:
                building = building.OrderBy(s => s.NameMaterial);
                break;
            }

            // пагинация
            var count = await building.CountAsync();

            var items = await building.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            // формируем модель представления
            BuildingViewModel viewModel = new BuildingViewModel
            {
                PageViewModel     = new PageViewModel(count, page, pageSize),
                SortViewModel     = new SortViewModels(sortBuild),
                FilterViewModel   = new FilterViewModel(_context.Contractors.ToList(), contr, nameMaterial),
                BuildingMaterials = items
            };

            return(View(viewModel));
        }