Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 private bool IsFirstTimeSetup()
 {
     if (_context.Ticket.ToList().Count <= 0)
     {
         _context.Ticket.RemoveRange(_context.Ticket);
         _context.SaveChanges();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        private void DownloadBankCurrencyMetadata(BCCContext context, string bankName)
        {
            IExchangeRateBank bank;

            if (Banks.TryGetValue(bankName, out bank))
            {
                List <ICurrencyMetada> metaData = bank.DownloadCurrencyMetada();
                foreach (ICurrencyData meta in metaData)
                {
                    SaveBankCurrencyMetada(context, meta);
                }
                context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        private void SaveBankCurrencyMetada(BCCContext context, ICurrencyMetada metaData)
        {
            CurrencyMetadata ret = context.CurrencyMetadata.Where(x => x.IsoName == metaData.ISOName).FirstOrDefault();

            if (ret == null)
            {
                if (string.IsNullOrWhiteSpace(metaData.ISOName))
                {
                    return;
                }
                if (metaData.Quantity < 1)
                {
                    return;
                }
                ret = new CurrencyMetadata()
                {
                    IsoName  = metaData.ISOName,
                    Name     = metaData.Name,
                    Quantity = metaData.Quantity,
                    Country  = metaData.Country
                };
                context.CurrencyMetadata.Add(ret);
                context.SaveChanges();
            }
            else
            {
                if (string.IsNullOrWhiteSpace(ret.Name) && !string.IsNullOrWhiteSpace(metaData.Name))
                {
                    ret.Name = metaData.Name;
                }
                if (string.IsNullOrWhiteSpace(ret.Country) && !string.IsNullOrWhiteSpace(ret.Country))
                {
                    ret.Country = metaData.Country;
                }
            }
        }