Пример #1
0
        // GET: /Measurement/
        public IActionResult Index(string sortOrder, string pageSize, string filter, string currentFilter, int?page)
        {
            ViewData["CurrentSort"]   = sortOrder;
            ViewData["NameSortParam"] = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";

            if (!string.IsNullOrEmpty(pageSize))
            {
                ViewData["SizePage"] = pageSize;
            }
            else if (string.IsNullOrEmpty(pageSize) & string.IsNullOrEmpty((string)ViewData["SizePage"]))
            {
                pageSize = (string)ViewData["SizePage"];
            }


            int sizeOfPage;

            if (int.TryParse(pageSize, out sizeOfPage) == false)
            {
                sizeOfPage = 12;
            }
            if (filter != null)
            {
                page = 1;
            }
            else
            {
                filter = currentFilter;
            }
            ViewData["CurrentFilter"] = filter;
            var collTag = _measurementRepository.MeasurementByFilter(filter);

            switch (sortOrder)
            {
            case "name_desc":
                collTag = collTag.OrderByDescending(s => s.Name);
                break;

            default:
                collTag = collTag.OrderBy(s => s.Name);
                break;
            }

            return(View(PagerList <Measurement> .Create(collTag, page ?? 1, sizeOfPage)));
        }