예제 #1
0
        public ActionResult Authors(string sortOrder, string currentFilter, string searchString, int?page)
        {
            if (!LoggedIn())
            {
                return(RedirectToAction("LoginAdmin", "Auth"));
            }

            if (!isAdmin())
            {
                return(RedirectToAction("Index", "Author"));
            }

            ViewBag.CurrentSort    = sortOrder;
            ViewBag.TitleSortParm  = string.IsNullOrEmpty(sortOrder) ? "title_desc" : "";
            ViewBag.StatusSortParm = sortOrder == "Status" ? "status_desc" : "Status";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            var authors = from a in authorHelper.GetAll() select a;

            if (!string.IsNullOrEmpty(searchString))
            {
                authors = authors.Where(a => a.Email.ToLower().Contains(searchString.ToLower()) || a.FullName.ToLower().Contains(searchString.ToLower()));
            }

            switch (sortOrder)
            {
            case "title_desc":
                authors = authors.OrderByDescending(a => a.FullName);
                break;

            case "Status":
                authors = authors.OrderBy(a => a.isVerified);
                break;

            case "status_desc":
                authors = authors.OrderByDescending(a => a.isVerified);
                break;

            default:
                authors = authors.OrderBy(a => a.FullName);
                break;
            }

            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(authors.ToPagedList(pageNumber, pageSize)));
        }