public ActionResult Index(int page = 1,int pageSize = 10)
 {
     TempData["pageSize"] = pageSize;
     TempData["page"] = page;
     List<BorrowEntry> borrowList = libRepo.BorrowEntryRepo.List();
     PageList<BorrowEntry> pglist = new PageList<BorrowEntry>(borrowList, page, pageSize);
     switch (pglist.Categorized())
     {
         case PageListResult.Ok: { return View(pglist); }
         case PageListResult.Empty:
             {
                 TempData["ErrorNoti"] = "No borrowed list to show.";
                 return View();
             }
         default:
             {
                 TempData["ErrorNoti"] = "Invalid list view parameter please refresh this page to try again.";
                 return View();
             }
     }
 }
Esempio n. 2
0
 public ActionResult ViewAll(int page = 1,int pageSize = 10)
 {
     TempData["pageSize"] = pageSize;
     TempData["page"] = page;
     List<News> newsList = libRepo.NewsRepo.List().OrderByDescending(news => news.PostTime).ToList();
     PageList<News> pglist = new PageList<News>(newsList, page, pageSize);
     switch (pglist.Categorized())
     {
         case PageListResult.Ok: { return View(pglist); }
         case PageListResult.Empty:
             {
                 TempData["ErrorNoti"] = "No news list to show now.";
                 return View();
             }
         default:
             {
                 TempData["ErrorNoti"] = "Invalid list view parameter please refresh this page to try again.";
                 return View();
             }
     }
 }
 public ActionResult BorrowHistory(int page = 1,int pageSize = 10)
 {
     string username;
     username = HttpContext.User.Identity.Name.ToString().Substring(2);
     Member currentMember = libRepo.MemberRepo.ListWhere(target => target.UserName == username).SingleOrDefault();
     List<BorrowEntry> EntryList = currentMember.GetRelatedBorrowEntry(ref libRepo);
     PageList<BorrowEntry> pglist = new PageList<BorrowEntry>(EntryList,page,pageSize);
     TempData["BorrowCount"] = EntryList.Count();
     switch (pglist.Categorized())
     {
         case PageListResult.Ok: { return View(pglist); }
         case PageListResult.Empty:
             {
                 TempData["ErrorNoti"] = "No borrow history to show.Please do transaction to see your history.";
                 return View();
             }
         default:
             {
                 TempData["ErrorNoti"] = "Invalid list view parameter please refresh this page to try again.";
                 return View();
             }
     }
 }
        public ActionResult Advance([Bind(Include = "BookName,Author,Publisher,Year,CallNumber")]Book bookToSearch,int page = 1,int pageSize = 10)
        {
            ModelState.Remove("BookName");
            ModelState.Remove("CallNumber");

            //Memorize search parameter to return to search page.
            TempData["BookName"] = bookToSearch.BookName;
            TempData["Author"] = bookToSearch.Author;
            TempData["Publisher"] = bookToSearch.Publisher;
            TempData["Year"] = bookToSearch.Year;
            TempData["Callno"] = bookToSearch.CallNumber;

            //Start timer
            Stopwatch Timer = new Stopwatch();
            Timer.Start();
            if (ModelState.IsValid)
            {
                List<Book> bookList;
                bookToSearch.BookName = (bookToSearch.BookName == null) ? "" : bookToSearch.BookName;
                bookToSearch.Author = (bookToSearch.Author == null) ? "" : bookToSearch.Author;
                bookToSearch.Publisher = (bookToSearch.Publisher == null) ? "" : bookToSearch.Publisher;
                bookToSearch.CallNumber = (bookToSearch.CallNumber == null) ? "" : bookToSearch.CallNumber.ToLower();
                if (bookToSearch.Year != null)
                {
                    bookList = libRepo.BookRepo.ListWhere(target => (target.BookName.Contains(bookToSearch.BookName)) &&
                        (target.CallNumber.ToLower().Contains(bookToSearch.CallNumber)) &&
                        (StringUtil.IsContains(target.Author, bookToSearch.Author)) &&
                       (StringUtil.IsContains(target.Publisher, bookToSearch.Publisher)) &&
                     (target.Year == bookToSearch.Year)).ToList();
                }

                else
                {
                    bookList = libRepo.BookRepo.ListWhere(target => (target.BookName.Contains(bookToSearch.BookName)) &&
                    (target.CallNumber.ToLower().Contains(bookToSearch.CallNumber)) &&
                    (StringUtil.IsContains(target.Author, bookToSearch.Author)) &&
                    (StringUtil.IsContains(target.Publisher, bookToSearch.Publisher))).ToList();
                }

                //Stop timer
                Timer.Stop();
                TempData["AdvanceSearch"] = "Advance";
                TempData["pageSize"] = pageSize;
                TempData["page"] = page;
                PageList<Book> pglist = new PageList<Book>(bookList, page, pageSize);
                switch (pglist.Categorized())
                {
                    case PageListResult.Ok: {
                        /* if result is not empty or null set FindTime in TempData by use
                         * ElapsedMilliseconds divide by 1000.0
                         * this will result in double value.
                         */
                        TempData["TotalResult"] = bookList.Count;
                        TempData["FindTime"] = Timer.ElapsedMilliseconds / 1000.0;
                        return View("Index", pglist);
                    }
                    case PageListResult.Empty:
                        {
                            TempData["ErrorNoti"] = "No book result found.";
                            return View("Index");
                        }
                    default:
                        {
                            TempData["ErrorNoti"] = "Invalid list view parameter please refresh this page to try again.";
                            return View("Index");
                        }
                }
            }
            else
                TempData["ErrorNoti"] = "Input string was not in a correct format.";
            return View("Index");
        }
        public ActionResult QuickSearch(string bookName,int page = 1,int pageSize = 10)
        {
            TempData["quicksearchkey"] = bookName;
            Stopwatch Timer = new Stopwatch();

            //Start timer
            Timer.Start();
            List<Book> bookList = libRepo.BookRepo.ListWhere(target => target.BookName.Contains(bookName));

            //Stop timer
            Timer.Stop();
            TempData["pageSize"] = pageSize;
            TempData["page"] = page;
            PageList<Book> pglist = new PageList<Book>(bookList, page, pageSize);
            switch (pglist.Categorized())
            {
                /* if result is not empty or null set FindTime in TempData by use
                 * ElapsedMilliseconds divide by 1000.0
                 * this will result in double value.
                 */
                case PageListResult.Ok: {
                    TempData["TotalResult"] = bookList.Count;
                    TempData["FindTime"] = Timer.ElapsedMilliseconds / 1000.0;
                    return View(pglist);
                }
                case PageListResult.Empty:
                    {
                        TempData["ErrorNoti"] = "No book result found.";
                        return View();
                    }
                default:
                    {
                        TempData["ErrorNoti"] = "Invalid list view parameter please refresh this page to try again.";
                        return View();
                    }
            }
        }
        public ActionResult Basic(string keyword, string searchType,int page = 1,int pageSize = 10)
        {
            //Start timer
            Stopwatch Timer = new Stopwatch();
            Timer.Start();

            //Memorized search parameter to return to search page.
            TempData["Keyword"] = keyword;
            ViewBag.SearchType = searchType;
            List<Book> bookList;
            if (searchType == "")
            {
                TempData["ErrorNoti"] = "Please select search type.";
                return View("Index");
            }
            else if (searchType == "BookName")
            {
                bookList = libRepo.BookRepo.ListWhere(target => target.BookName.Contains(keyword)).OrderBy(booksort => booksort.BookName).ToList();
            }
            else if (searchType == "Author")
            {
                bookList = libRepo.BookRepo.ListWhere(target => StringUtil.IsContains(target.Author,keyword)).OrderBy(booksort => booksort.BookName).ToList();

            }
            else if (searchType == "Publisher")
            {
                bookList = libRepo.BookRepo.ListWhere(target => StringUtil.IsContains(target.Publisher, keyword)).OrderBy(booksort => booksort.BookName).ToList();
            }
            else if (searchType == "Callno")
            {
                bookList = libRepo.BookRepo.ListWhere(target => target.CallNumber.ToLower().Contains(keyword.ToLower())).OrderBy(booksort => booksort.CallNumber).ToList();
            }
            else if (searchType == "Year")
            {
                try
                {
                    if (keyword != "")
                    {
                        int year = int.Parse(keyword);
                        bookList = libRepo.BookRepo.ListWhere(target => target.Year == year).OrderBy(booksort => booksort.BookName).ToList();
                    }
                    else
                    {
                        bookList = libRepo.BookRepo.List();
                    }
                }
                catch (FormatException)
                {
                    TempData["ErrorNoti"] = "Input string was not in a correct format.";
                    return View("Index");
                }
            }
            else
            {
                TempData["ErrorNoti"] = "Something was error.";
                return View("Index");
            }
            //Stop timer
            Timer.Stop();
            TempData["pageSize"] = pageSize;
            TempData["page"] = page;
            PageList<Book> pglist = new PageList<Book>(bookList, page, pageSize);
            switch (pglist.Categorized())
            {
                /* if result is not empty or null set FindTime in TempData by use
                 * ElapsedMilliseconds divide by 1000.0
                 * this will result in double value.
                 */
                case PageListResult.Ok: {
                    TempData["TotalResult"] = bookList.Count;
                    TempData["FindTime"] = Timer.ElapsedMilliseconds /1000.0;
                    return View("Index", pglist);
                }
                case PageListResult.Empty:
                    {
                        TempData["ErrorNoti"] = "No book result found.";
                    return View("Index");
                    }
                default:
                    {
                        TempData["ErrorNoti"] = "Invalid list view parameter please refresh this page to try again.";
                        return View("Index");
                    }
            }
        }