public async Task <IActionResult> Index(string CurrentFilter, string sortOrder, string searchString, int?pageNumber)
        {
            ViewData["CurrentSort"] = sortOrder;
            ViewData["NameSort"]    = String.IsNullOrEmpty(sortOrder) ? "author" : "";
            ViewData["DescSort"]    = sortOrder == "desc_descending" ? "desc" : "desc_descending";

            if (searchString != null)
            {
                pageNumber = 1;
            }
            else
            {
                searchString = CurrentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            List <Quote> quotes = new List <Quote>();

            await foreach (var quote in _quotesRepository.GetQuotes())
            {
                quotes.Add(quote);
            }

            if (!String.IsNullOrEmpty(searchString))
            {
                quotes = quotes.Where(q => q.Author.Contains(searchString)).ToList();
            }

            switch (sortOrder)
            {
            case "author":
                quotes = quotes.OrderByDescending(q => q.Author).ToList();
                break;

            case "desc":
                quotes = quotes.OrderBy(q => q.Description).ToList();
                break;

            case "desc_descending":
                quotes = quotes.OrderByDescending(q => q.Description).ToList();
                break;

            default:
                quotes = quotes.OrderBy(q => q.Author).ToList();
                break;
            }

            int pageSize = 10;

            return(View(PaginatedList <Quote> .Create(quotes, pageNumber ?? 1, pageSize)));
        }
Exemple #2
0
        public async Task <IActionResult> Quote()
        {
            List <Quote> quotes = new List <Quote>();

            await foreach (var quote in  _quotesRepository.GetQuotes())
            {
                quotes.Add(quote);
            }

            if (quotes.Count() == 0)
            {
                return(NotFound());
            }
            var response = quotes.OrderBy(r => Guid.NewGuid()).Take(1).First();

            response.Author = "";

            return(Ok(Json(response)));
        }
Exemple #3
0
 public ActionResult <IEnumerable <QuoteModel> > Get()
 {
     return(_quotesRepository.GetQuotes().ToList());
 }
Exemple #4
0
 public async Task <ObjectResult> GetQuotes()
 {
     return(Ok(await repository.GetQuotes()));
 }