Ejemplo n.º 1
0
 public SortSectionViewModel(SectionsSortState sortOrder)
 {
     BeginAndEndAscSort = sortOrder == SectionsSortState.BeginAndEndAsc ? SectionsSortState.BeginAndEndDesc : SectionsSortState.BeginAndEndAsc;
     SectionNameAscSort = sortOrder == SectionsSortState.SectionNameAsc ? SectionsSortState.SectionNameDesc : SectionsSortState.SectionNameAsc;
     StreetNameAscSort  = sortOrder == SectionsSortState.StreetNameAsc ? SectionsSortState.StreetNameDesc : SectionsSortState.StreetNameAsc;
     Current            = sortOrder;
 }
Ejemplo n.º 2
0
        // GET: Sections
        public IActionResult Index(int?beginAndEnd, string sectionName, string streetName, int page = 1, SectionsSortState sortOrder = SectionsSortState.BeginAndEndAsc)
        {
            int pageSize = 10;
            IQueryable <Sections> source = _context.Sections.Include(x => x.Street);

            if (beginAndEnd != 0 && beginAndEnd != null)
            {
                source = source.Where(x => x.BeginAndEnd == beginAndEnd);
            }
            if (sectionName != null)
            {
                source = source.Where(x => x.SectionName.Contains(sectionName));
            }
            if (streetName != null)
            {
                source = source.Where(x => x.Street.StreetName.Contains(streetName));
            }


            switch (sortOrder)
            {
            case SectionsSortState.BeginAndEndAsc:
                source = source.OrderBy(x => x.BeginAndEnd);
                break;

            case SectionsSortState.BeginAndEndDesc:
                source = source.OrderByDescending(x => x.BeginAndEnd);
                break;

            case SectionsSortState.SectionNameAsc:
                source = source.OrderBy(x => x.SectionName);
                break;

            case SectionsSortState.SectionNameDesc:
                source = source.OrderByDescending(x => x.SectionName);
                break;

            case SectionsSortState.StreetNameAsc:
                source = source.OrderBy(x => x.Street.StreetName);
                break;

            case SectionsSortState.StreetNameDesc:
                source = source.OrderByDescending(x => x.Street.StreetName);
                break;

            default:
                source = source.OrderBy(x => x.SectionName);
                break;
            }



            var count = source.Count();
            IEnumerable <Sections> items = source.Skip((page - 1) * pageSize).Take(pageSize);
            //var items = source.ToList();
            PageViewModel     pageView = new PageViewModel(count, page, pageSize);
            SectionsViewModel ivm      = new SectionsViewModel
            {
                PageViewModel   = pageView,
                SortViewModel   = new SortSectionViewModel(sortOrder),
                FilterViewModel = new FilterSectionsViewModel(beginAndEnd, sectionName, streetName),
                Sections        = items,
                Users           = _context.User
            };

            return(View(ivm));
        }