示例#1
0
        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)));
            }
        }
示例#2
0
        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));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
 }