public async Task <IActionResult> Author(int mode, Guid id) { List <Quote> quotes = new List <Quote>(); await foreach (var quote in _quotesRepository.GetQuotes()) { quotes.Add(quote); } if (mode == 2) { List <Quote> quote = new List <Quote>(quotes.Where(q => q.Id != id).OrderBy(r => Guid.NewGuid()).Take(2)); Quote answer = await _quotesRepository.GetQuote(id); List <string> authors = new List <string>(); authors.Add(answer.Author); authors.AddRange(quote.Select(q => q.Author)); authors = authors.OrderBy(a => Guid.NewGuid()).ToList(); return(Ok(Json(authors))); } else { Quote response = quotes.OrderBy(r => Guid.NewGuid()).Take(2).First(); string author = response.Author; return(Ok(Json(author))); } }
public async Task <IActionResult> Details(Guid id) { if (id == null) { return(NotFound()); } var quote = await _quotesRepository.GetQuote(id); if (quote == null) { return(NotFound()); } return(View(quote)); }
public async Task <ReadOnlyQuote> HandleAsync(UpdateQuote command) { var quote = await _quotesRepository.GetQuote(command.Id); var readonlyQuote = new ReadOnlyQuote(quote.Id, command.Phrase, command.Attribution, quote.CreatedAt, quote.UpdatedAt); return(await _quotesRepository.UpdateQuote(readonlyQuote)); }
public ActionResult <QuoteModel> Get(int id) { var quote = _quotesRepository.GetQuote(id); if (quote != null) { return(quote); } return(NotFound()); }
public async Task <ReadOnlyQuote> HandleAsync(GetQuoteById query) { return(await _quotesRepository.GetQuote(query.Id)); }