Ejemplo n.º 1
0
 public void SaveExchnageRateHistory()
 {
     try
     {
         var rate = dbContext.OperationZoneExchangeRates.Where(p => p.IsActive == true).ToList();
         if (rate != null)
         {
             OperationZoneExchangeRateHistory hrate;
             foreach (var Obj in rate)
             {
                 hrate = new OperationZoneExchangeRateHistory();
                 hrate.OperationZoneId = Obj.OperationZoneId;
                 hrate.CurrencyCode    = Obj.CurrencyCode;
                 hrate.ExchangeRate    = Obj.ExchangeRate;
                 hrate.ExchangeType    = Obj.ExchangeType;
                 hrate.StartDate       = DateTime.UtcNow.AddDays(-1);
                 hrate.FinishDate      = DateTime.UtcNow;
                 dbContext.OperationZoneExchangeRateHistories.Add(hrate);
                 dbContext.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Ejemplo n.º 2
0
        public void SaveExchangeRate(List <FrayteExchangeRate> exchangeRate)
        {
            try
            {
                OperationZoneExchangeRate exRate;
                if (exchangeRate != null && exchangeRate.Count > 0)
                {
                    foreach (var rr in exchangeRate)
                    {
                        if (rr.OperationZoneExchangeRateId > 0)
                        {
                            exRate = dbContext.OperationZoneExchangeRates.Find(rr.OperationZoneExchangeRateId);
                            if (exRate != null)
                            {
                                exRate.OperationZoneId = rr.OperationZone.OperationZoneId;
                                if (rr.IsActive)
                                {
                                    exRate.ExchangeRate = rr.ExchangeRate;
                                }
                                else
                                {
                                    exRate.ExchangeRate = 0;
                                }
                                exRate.IsActive = rr.IsActive;
                                dbContext.Entry(exRate).State = System.Data.Entity.EntityState.Modified;
                                dbContext.SaveChanges();
                            }

                            //Insert ExchangeRate In History
                            OperationZoneExchangeRateHistory hrate = new OperationZoneExchangeRateHistory();
                            hrate.OperationZoneId = rr.OperationZone.OperationZoneId;
                            hrate.CurrencyCode    = rr.CurrencyDetail.CurrencyCode;
                            hrate.ExchangeRate    = rr.ExchangeRate;
                            hrate.ExchangeType    = rr.ExchangeType;
                            hrate.StartDate       = DateTime.UtcNow.AddDays(-1);
                            hrate.FinishDate      = DateTime.UtcNow;
                            dbContext.OperationZoneExchangeRateHistories.Add(hrate);
                            dbContext.SaveChanges();
                        }
                        else
                        {
                            exRate = dbContext.OperationZoneExchangeRates.Where(p => p.OperationZoneId == rr.OperationZone.OperationZoneId &&
                                                                                p.CurrencyCode == rr.CurrencyDetail.CurrencyCode).FirstOrDefault();
                            if (exRate != null)
                            {
                                exRate.ExchangeRate = rr.IsActive ? rr.ExchangeRate : 0;
                                exRate.IsActive     = rr.IsActive;
                                dbContext.SaveChanges();
                            }
                            else if (rr.IsActive)
                            {
                                exRate = new OperationZoneExchangeRate();
                                exRate.OperationZoneId = rr.OperationZone.OperationZoneId;
                                exRate.CurrencyCode    = rr.CurrencyDetail.CurrencyCode;
                                exRate.ExchangeRate    = rr.ExchangeRate;
                                exRate.ExchangeType    = rr.ExchangeType;
                                exRate.IsActive        = true;
                                dbContext.OperationZoneExchangeRates.Add(exRate);
                                dbContext.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }