コード例 #1
0
        // GET: Experiments
        public IActionResult Index(string nameequipment, string daterelease, int page = 1, EquipmentsSortState sortOrder = EquipmentsSortState.NameEquipmentAsc)
        {
            int pageSize = 10;
            IQueryable <Equipments> source = _context.Equipments;

            if (nameequipment != null)
            {
                source = source.Where(x => x.NameEquipment == nameequipment);
            }
            if (daterelease != null)
            {
                source = source.Where(x => x.DateRelease == DateTime.Parse(daterelease));
            }

            switch (sortOrder)
            {
            case EquipmentsSortState.NameEquipmentAsc:
                source = source.OrderBy(x => x.NameEquipment);
                break;

            case EquipmentsSortState.NameEquipmentDesc:
                source = source.OrderByDescending(x => x.NameEquipment);
                break;

            case EquipmentsSortState.DateReleaseAsc:
                source = source.OrderBy(x => x.DateRelease);
                break;

            case EquipmentsSortState.DateReleaseDesc:
                source = source.OrderByDescending(x => x.DateRelease);
                break;
            }



            var                 count    = source.Count();
            var                 items    = source.Skip((page - 1) * pageSize).Take(pageSize);
            PageViewModel       pageView = new PageViewModel(count, page, pageSize);
            EquipmentsViewModel ivm      = new EquipmentsViewModel
            {
                PageViewModel   = pageView,
                SortViewModel   = new SortEquipmentsViewModel(sortOrder),
                FilterViewModel = new FilterEquipmentsViewModel(nameequipment, daterelease),
                Equipments      = items
            };

            return(View(ivm));
        }
コード例 #2
0
 public SortEquipmentsViewModel(EquipmentsSortState sortOrder)
 {
     NameEquipmentAscSort = sortOrder == EquipmentsSortState.NameEquipmentAsc ? EquipmentsSortState.NameEquipmentDesc : EquipmentsSortState.NameEquipmentAsc;
     DateReleaseAscSort   = sortOrder == EquipmentsSortState.DateReleaseAsc ? EquipmentsSortState.DateReleaseDesc : EquipmentsSortState.DateReleaseAsc;
     Current = sortOrder;
 }