示例#1
0
 public CurrencyController(ICurrencyConverterService currencyConverterService, IRequestLoggerService requestLoggerService,
                           CurrencyConverterContext context)
 {
     _currencyConverterService = currencyConverterService;
     _requestLoggerService     = requestLoggerService;
     _context = context;
 }
示例#2
0
 private void MigrateDatabase()
 {
     using (var dbContext = new CurrencyConverterContext())
     {
         dbContext.Database.Migrate();
     }
 }
示例#3
0
 private static void CleanRatesTable()
 {
     using (var dbContext = new CurrencyConverterContext())
     {
         var deleteQuery = $"delete from {nameof(dbContext.Rates)}";
         dbContext.Database.ExecuteSqlCommand(deleteQuery);
     }
 }
示例#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;
 }
示例#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();
     }
 }
示例#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);
        }
 public DummyController(CurrencyConverterContext ctx)
 {
     _ctx = ctx;
 }
示例#8
0
 public CurrencyConverterRepo(CurrencyConverterContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }