private bool UpdateCurrencies(IList <Currency> loadedCurrencies, WalutyDBContext context)
        {
            DbSet <Currency> currenciesDbSet = context.Currencies;

            try
            {
                foreach (Currency currency in loadedCurrencies)
                {
                    var currentCurrency    = currenciesDbSet.Include(x => x.ListOfRecords).SingleOrDefault(x => x.Name.ToLower() == currency.Name.ToLower());
                    var latestCurrencyDate = currentCurrency.ListOfRecords.Max(x => x.Date);

                    var currencyRecordsToUpdate = currency.ListOfRecords.Where(x => x.Date > latestCurrencyDate).ToList();

                    currentCurrency.ListOfRecords.AddRange(currencyRecordsToUpdate);
                }
                context.SaveChanges();
                return(true);
            }
            catch (DbUpdateException e)
            {
                Log.Logger.Error("Couldn't update the database");
                Log.Logger.Error(e.Message);
            }

            return(false);
        }
        public bool Process(WalutyDBContext context)
        {
            DateTime currentDate         = DateTime.Now;
            string   fullPathToDirectory = Path.Combine(Directory.GetParent(Environment.CurrentDirectory).Parent.FullName,
                                                        _fileFolderName,
                                                        currentDate.ToString("ddMMyyyy"));
            bool             downloaderResult = false;
            bool             unzipperResult   = false;
            bool             updateResult     = false;
            IList <Currency> loadedCurrencies = new List <Currency>();

            downloaderResult = _downloader.DownloadFilesAsync(_databaseZipFileLink, _databaseContentFileLink, fullPathToDirectory, currentDate, _contentFileName, _databaseFileName).Result;
            unzipperResult   = _unzipper.UnzipFile(_databaseFileName, fullPathToDirectory);

            if (downloaderResult && unzipperResult)
            {
                loadedCurrencies = _loader.GetListOfAllCurrencies(fullPathToDirectory);

                updateResult = UpdateCurrencies(loadedCurrencies, context);

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
 public AdminController(IUserServices userServices, IMapper mapper, RoleManager <IdentityRole> roleManager,
                        ICurrencyFilesUpdater currencyFilesUpdater, WalutyDBContext context)
 {
     _userServices         = userServices;
     _mapper               = mapper;
     _roleManager          = roleManager;
     _currencyFilesUpdater = currencyFilesUpdater;
     _context              = context;
 }
Esempio n. 4
0
 public CurrencyRepository(WalutyDBContext walutyDBContext)
 {
     _walutyDBContext = walutyDBContext;
 }
 public FavoritesController(UserManager <User> userManager, WalutyDBContext context)
 {
     _userManager = userManager;
     _context     = context;
 }