Ejemplo n.º 1
0
 public CurrencyController(ICurrencyConverterService currencyConverterService, IRequestLoggerService requestLoggerService,
                           CurrencyConverterContext context)
 {
     _currencyConverterService = currencyConverterService;
     _requestLoggerService     = requestLoggerService;
     _context = context;
 }
Ejemplo n.º 2
0
 private void MigrateDatabase()
 {
     using (var dbContext = new CurrencyConverterContext())
     {
         dbContext.Database.Migrate();
     }
 }
Ejemplo n.º 3
0
 private static void CleanRatesTable()
 {
     using (var dbContext = new CurrencyConverterContext())
     {
         var deleteQuery = $"delete from {nameof(dbContext.Rates)}";
         dbContext.Database.ExecuteSqlCommand(deleteQuery);
     }
 }
Ejemplo n.º 4
0
 public RateService(ILoggerFactory loggerFactory, IDoubleFlow cache, IHttpClientFactory clientFactory,
                    IOptions <CurrencyLayerOptions> options, CurrencyConverterContext context)
 {
     _cache         = cache;
     _clientFactory = clientFactory;
     _context       = context;
     _logger        = loggerFactory.CreateLogger <RateService>();
     _options       = options.Value;
 }
Ejemplo n.º 5
0
 private static void InsertNewRate(string usdCurrencyName, decimal usdRateValue)
 {
     using (var dbContext = new CurrencyConverterContext())
     {
         var usdRate = new RateValue {
             RateValueId = 1, Currency = usdCurrencyName, Value = usdRateValue
         };
         dbContext.Rates.Add(usdRate);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 6
0
        public async Task <bool> LogRequest(string url, bool nbpApi, CurrencyConverterContext _context)
        {
            var log = new RequestLog()
            {
                Date    = DateTime.Now,
                Request = String.Concat(nbpApi ? Commons.NBP_ROUTE : Commons.API_ROUTE, url)
            };

            _context.RequestLogs.Add(log);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
 public DummyController(CurrencyConverterContext ctx)
 {
     _ctx = ctx;
 }
Ejemplo n.º 8
0
 public CurrencyConverterRepo(CurrencyConverterContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }