public async Task <JsonResult> GetQuotes() { QuotesData quotesData = new QuotesData(); using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync("https://opinionated-quotes-api.gigalixirapp.com/v1/quotes")) { string apiResponse = await response.Content.ReadAsStringAsync(); quotesData = JsonConvert.DeserializeObject <QuotesData>(apiResponse); foreach (var quote in quotesData.Quotes) { QuoteMap newQuote = new QuoteMap() { Author = quote.Author, Language = quote.Language, Quote = quote.quote, Tags = string.Join(",", quote.Tags.ToArray()) }; _quoteService.Add(newQuote); } } } //TODO: Save to our DB return(Json(quotesData)); }
public void AddQuote(QuoteMap quote) { try { _context.Quotes.Add(quote); _context.SaveChanges(); _logger.LogInformation("Quote Addet to DB"); } catch (Exception ex) { _logger.LogError("Quote NOT Added to DB |" + ex); throw; } }
public void AddQuote(QuoteMap quote) { try { // "INSERT INTO ....VALUES " _context.Quotes.Add(quote); _context.SaveChanges(); _logger.LogInformation("Quote added in DB"); } catch (Exception ex) { _logger.LogError("Quote added in DB | " + ex); throw; } }
public void Add(QuoteMap quote) { _bookRepository.AddQuote(quote); }