Example #1
0
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
        public async Task <IActionResult> Index(int?whichpage, int?perpage, int?numpages)
//        public async Task<IActionResult> Index(int? whichpage, int? perpage, int? numpages, IFormCollection collection)
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
        {
            string airline = Request.Form["Airline"].ToString();

            ViewBag.AirlineName = airline;

            int    WhichPage = whichpage ?? 1;
            int    PerPage   = perpage ?? 25;
            int    NumPages  = numpages ?? 0;
            string SortOrder = "airline";

            string swaps = Request.Form["Swaps"];

            // THIS WILL WORK TOO!
            //string airline2 = collection["Airline"].ToString();
            //            IActionResult bags = await GetBags(collection);
            SortedCriteria = Request.Form;
            IActionResult bags = await GetBags(Request.Form);

            var okResult = bags as OkObjectResult;
            var baglist  = okResult.Value as List <Bagsmvc>;

            if (Request.Form["Swaps"].ToString() == "on")
//                if (collection["Swaps"].ToString() == "on")
            {
                ViewBag.Swaps = 1;
                baglist       = baglist.OrderByDescending(s => s.DateSwapAdded).ThenBy(x => x.Airline).ToList();
            }
            else
            {
                ViewBag.Swaps = 0;
                baglist       = baglist.OrderBy(s => s.Airline).ToList();
            }

            // Now we have to fetch only the page of interest.
            // baglist = CreatePagination(baglist, WhichPage, PerPage, ref NumPages);

            ViewBag.SortOrder = SortOrder;
            ViewBag.WhichPage = WhichPage;
            ViewBag.NumPages  = NumPages;
            ViewBag.PerPage   = PerPage;

            ViewBag.NameSortParm = "airline_desc";
            ViewBag.YearSortParm = "year";

            BagsImageViewModel bivm = new BagsImageViewModel();

            bivm.Bags     = baglist;
            bivm.Bagtypes = await GetBagtypes();

            return(View(bivm));
        }
Example #2
0
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
        public async Task <IActionResult> Index(int?id, string sortorder, int?whichpage, int?perpage, int?numpages, IFormCollection collection)
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
        {
            List <Bagsmvc> baglist = new List <Bagsmvc>();
            IActionResult  bags;

            ViewBag.Swaps = 0;

            // If there's pagination or sorting, we have to get data using the saved state
            if (whichpage != null || sortorder != null)
            {
                collection = SortedCriteria;
            }

            // Default to sorting by airline
            string SortOrder = sortorder ?? "airline";
//            sortorder = sortorder != null ? sortorder : "airline";

            int WhichPage = whichpage ?? 1;
            int NumPages  = numpages ?? 0;
            int PerPage   = perpage ?? 25;

            if (collection.Count == 0 || id != null)
            {
                // Returns no bags
                bags = await GetBags(null);
            }
            else
            {
                // Returns bags selected on the form
                bags = await GetBags(collection);
            }

            if (bags is null)
            {
                if (id == null)
                {
                    baglist = null;
                }
                else
                {
                    // Get this bag from the cache and add it to the list
                    var allbags = await _cache.GetFromTable(_context.Bags);

                    var b = allbags.FirstOrDefault(x => x.Id == id);
                    baglist.Add(b);
                }
            }
            else
            {
                var okResult = bags as OkObjectResult;
                baglist = okResult.Value as List <Bagsmvc>;
            }

            // Sorting columns
            if (baglist != null)
            {
                if (collection["Swaps"].ToString() == "on")
                {
                    ViewBag.Swaps = 1;

                    switch (SortOrder)
                    {
                    case "airline_desc":
                        baglist = baglist.OrderByDescending(x => x.DateSwapAdded).ThenByDescending(s => s.Airline).ToList();
                        ViewBag.NameSortParm = "airline";
                        ViewBag.YearSortParm = "year";
                        break;

                    case "year":
                        baglist = baglist.OrderByDescending(x => x.DateSwapAdded).ThenBy(s => s.Year).ToList();
                        ViewBag.NameSortParm = "airline";
                        ViewBag.YearSortParm = "year_desc";
                        break;

                    case "year_desc":
                        baglist = baglist.OrderByDescending(x => x.DateSwapAdded).ThenByDescending(s => s.Year).ToList();
                        ViewBag.NameSortParm = "airline";
                        ViewBag.YearSortParm = "year";
                        break;

                    case "airline":
                        baglist = baglist.OrderByDescending(x => x.DateSwapAdded).ThenBy(s => s.Airline).ToList();
                        ViewBag.NameSortParm = "airline_desc";
                        ViewBag.YearSortParm = "year";
                        break;

                    default:
                        baglist = null;
                        break;
                    }
                }
                else
                {
                    switch (SortOrder)
                    {
                    case "airline_desc":
                        baglist = baglist.OrderByDescending(s => s.Airline).ToList();
                        ViewBag.NameSortParm = "airline";
                        ViewBag.YearSortParm = "year";
                        break;

                    case "year":
                        baglist = baglist.OrderBy(s => s.Year).ToList();
                        ViewBag.NameSortParm = "airline";
                        ViewBag.YearSortParm = "year_desc";
                        break;

                    case "year_desc":
                        baglist = baglist.OrderByDescending(s => s.Year).ToList();
                        ViewBag.NameSortParm = "airline";
                        ViewBag.YearSortParm = "year";
                        break;

                    case "airline":
                        baglist = baglist.OrderBy(s => s.Airline).ToList();
                        ViewBag.NameSortParm = "airline_desc";
                        ViewBag.YearSortParm = "year";
                        break;

                    default:
                        baglist = null;
                        break;
                    }
                }
            }

            // Now we have to fetch only the page of interest.
//            baglist = CreatePagination(baglist, WhichPage, PerPage, ref NumPages);

            ViewBag.SortOrder = SortOrder;
            ViewBag.WhichPage = WhichPage;
            ViewBag.NumPages  = NumPages;
            ViewBag.PerPage   = PerPage;

            BagsImageViewModel bivm = new BagsImageViewModel();

            bivm.Bags     = baglist;
            bivm.Bagtypes = await GetBagtypes();

            return(View(bivm));
        }