示例#1
0
        private void SaveERTciket(BCCContext context, ExchangeRateTicket eRTicket, string bankName)
        {
            if (eRTicket == null || bankName == null)
            {
                throw new BCCERMNullReference();
            }

            Ticket ticket = context.Ticket.Where(x => x.Date == eRTicket.TicketDate && x.BankShortName == bankName).FirstOrDefault();

            if (ticket == null)
            {
                ticket = new Ticket()
                {
                    BankShortName = bankName,
                    Date          = eRTicket.TicketDate
                };
                context.Ticket.Add(ticket);
                context.SaveChanges();
            }
            ICurrencyData[] eRData = eRTicket.GetExchangeRateData();
            foreach (ICurrencyData data in eRData)
            {
                Currency currency = new Currency();
                currency.TicketId = ticket.Id;
                currency.IsoName  = data.ISOName;
                currency.Buy      = data.Buy;
                currency.Sell     = data.Sell;
                if (context.Currency.FirstOrDefault(x => x.IsoName == currency.IsoName && x.TicketId == currency.TicketId) == null)
                {
                    context.Add(currency);
                }
            }
            context.SaveChanges();
        }
示例#2
0
 private void DownloadTodaysBankTicket(string bankName, BCCContext context)
 {
     try
     {
         Ticket ticket = context.Ticket.FirstOrDefault(x => x.BankShortName == bankName && x.Date.Day == DateTime.Now.Day && x.Date.Month == DateTime.Now.Month && x.Date.Year == DateTime.Now.Year);
         if (ticket == null)
         {
             IExchangeRateBank bank;
             if (Banks.TryGetValue(bankName, out bank))
             {
                 if (bank.TodaysTicketIsAvailable())
                 {
                     ExchangeRateTicket erTicket = bank.DownloadTodaysTicket();
                     SaveERTciket(context, erTicket, bankName);
                 }
             }
         }
     }
     catch (BCCCoreException ex)
     {
         //TODO: MM add logging
     }
 }