コード例 #1
0
        // GET: Report for BorrowedBookBetweenDates
        public ActionResult BorrowedBookBetweenDates(ReportViewModel report, string sortBy, string BorrowedBookBetweenDatesDateFrom, string BorrowedBookBetweenDatesDateTo)
        {
            ViewBag.SortTitleParameter           = sortBy == "Book" ? "Book_desc" : "Book";
            ViewBag.SortByFirst_NameParameter    = sortBy == "First Name" ? "First Name desc" : "First Name";
            ViewBag.SortByLast_NameParameter     = sortBy == "Last Name" ? "Last Name desc" : "Last Name";
            ViewBag.SortByYearParameter          = sortBy == "Year" ? "Year desc" : "Year";
            ViewBag.SortByLeft_QuantityParameter = sortBy == "Left Quantity" ? "Left Quantity desc" : "Left Quantity";
            if (!ModelState.IsValid)
            {
                return(View("Report"));
            }
            var result = _context.BorrowedBookBetweenDates(report.BorrowedBookBetweenDatesDateFrom, report.BorrowedBookBetweenDatesDateTo).ToList();

            if (result == null)
            {
                return(HttpNotFound());
            }
            //Session["BorrowedBookBetweenDatesTmp"] = result;
            //Session["BorrowedBookBetweenDatesTmpForPdf"] = result;
            switch (sortBy)
            {
            case "Book_desc":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderByDescending(b => b.Title).ToList();
                break;

            case "Book":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderBy(b => b.Title).ToList();
                break;

            case "First Name desc":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderByDescending(b => b.First_Name).ToList();
                break;

            case "First Name":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderBy(b => b.First_Name).ToList();
                break;

            case "Last Name desc":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderByDescending(b => b.Last_Name).ToList();
                break;

            case "Last Name":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderBy(b => b.Last_Name).ToList();
                break;

            case "Year desc":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderByDescending(b => b.Year).ToList();
                break;

            case "Year":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderBy(b => b.Year).ToList();
                break;

            case "Left Quantity desc":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderByDescending(b => b.Left_Quantity).ToList();
                break;

            case "Left Quantity":
                result = _context.BorrowedBookBetweenDates(Convert.ToDateTime(BorrowedBookBetweenDatesDateFrom), Convert.ToDateTime(BorrowedBookBetweenDatesDateTo)).OrderBy(b => b.Left_Quantity).ToList();
                break;
            }
            return(View(result));
        }