Exemplo n.º 1
0
        /// <summary>
        /// Update the Data Base with quotes
        /// </summary>
        /// <returns>number of Quotes</returns>
        public async Task <int> UpdateQuotesToBaseAsync()
        {
            QuoteService       quateService  = new QuoteService();
            CurrencylayerModel currencylayer = await GetQuotes();

            foreach (var item in currencylayer.Quotes)
            {
                var newQuote = new QuoteModel
                {
                    Id    = item.Key,
                    Value = item.Value
                };


                if (!_quoteService.Exists(newQuote.Id))
                {
                    await _quoteService.PostOne(newQuote);
                }
                else
                {
                    await _quoteService.PutOne(newQuote.Id, newQuote);
                }


                //if (!_context.Quotes.Any(e => e.Id == newQuote.Id))
                //{
                //    _context.Quotes.Add(newQuote);
                //    await _context.SaveChangesAsync();
                //}
                //else
                //{
                //    _context.Entry(newQuote).State = EntityState.Modified;
                //    await _context.SaveChangesAsync();
                //}
            }

            return(currencylayer.Quotes.Count);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 public CurrencylayerService()
 {
     _context      = new DataContext();
     _quoteService = new QuoteService();
 }