示例#1
0
        /// <summary>
        /// Validates the FXRates data read from CSV.
        /// </summary>
        /// <param name="csvFxRatesData">List of FxRates read from CSV File.</param>
        internal async Task <ValidatedFxRateManualImport> ProcessManualFxRatesImport(List <FxRateCsvLine> csvFxRatesData)
        {
            IEnumerable <Currency> currencies = (await _currencyRepository.GetAllAsync(true)).ToList();

            List <DateTime?> excelDate = new List <DateTime?>();

            foreach (var item in csvFxRatesData)
            {
                if (!string.IsNullOrEmpty(item.Date))
                {
                    excelDate.Add(Convert.ToDateTime(DateTime.ParseExact(item.Date, "yyyyMMdd", CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")));
                }
            }

            IEnumerable <FxRateRecord> existingFxRateRecords = (await _fxRateRepository.GetAllAsync(excelDate, FxRateViewMode.Daily)).ToList();

            var validatedFxRateDataForReport = ValidateData(csvFxRatesData, currencies, existingFxRateRecords);

            List <FxRateRecord> fxRatesToBeStaged = ConvertToFxRateRecord(csvFxRatesData.Where(i => validatedFxRateDataForReport.GoodData.LineNumberWithCurrency.Keys.Any(y => y == i.LineNumber)).ToList());

            fxRatesToBeStaged.AddRange(ConvertToFxRateRecord(csvFxRatesData.Where(i => validatedFxRateDataForReport.WarningData.Any(j => j.LineNumberWithCurrency.Keys.Any(y => y == i.LineNumber))).ToList()));

            // Save valid data into stage storage
            validatedFxRateDataForReport.ImportId = await _fxRateRepository.InsertIntoStageFxRate(fxRatesToBeStaged);

            return(validatedFxRateDataForReport);
        }
示例#2
0
        public async Task <ActionResult <CollectionViewModel <FxRate> > > GetAsync([FromQuery] DateTime?fxRateDate, [FromQuery] string viewMode = FxRateViewMode.Spot, [FromQuery] bool inactiveCurrencies = false)
        {
            if (fxRateDate == null && viewMode != FxRateViewMode.Spot)
            {
                return(BadRequest("The fxRateDate is required for viewMode other than Spot."));
            }

            if (viewMode != FxRateViewMode.Spot && viewMode != FxRateViewMode.Daily && viewMode != FxRateViewMode.Monthly)
            {
                return(BadRequest("Invalid value for viewMode."));
            }

            IEnumerable <Currency> currencies = (await _currencyRepository.GetAllAsync(inactiveCurrencies)).ToList();
            List <DateTime?>       dates      = new List <DateTime?>();

            dates.Add(fxRateDate);
            IEnumerable <FxRateRecord> fxRateRecords = await _fxRateRepository.GetAllAsync(dates, viewMode);

            var fxRatesJoinList =
                (from fxRate in fxRateRecords
                 join currency in currencies on fxRate.CurrencyCodeFrom equals currency.CurrencyCode into currenciesFrom
                 from cf in currenciesFrom.DefaultIfEmpty()
                 join currency in currencies on fxRate.CurrencyCodeTo equals currency.CurrencyCode into currenciesTo
                 from ct in currenciesTo.DefaultIfEmpty()
                 select new { FxRate = fxRate, CurrencyFrom = cf, CurrencyTo = ct }).ToList();

            // Filters out the values which do not meet the codes & types (for ex, EUR=>INR, or USD=>EUR if EUR is of type 'M')
            var fxRateRecordsFiltered = fxRatesJoinList
                                        .Where(r => (r.CurrencyFrom != null && r.CurrencyTo != null) && (r.CurrencyFrom.IsDollar() || r.CurrencyTo.IsDollar()))
                                        .Where(r => (r.CurrencyFrom != null && r.CurrencyFrom.IsDollar() && r.CurrencyTo.RoeType == "D") ||
                                               (r.CurrencyTo != null && r.CurrencyFrom.RoeType == "M" && r.CurrencyTo.IsDollar())).ToList();

            var fxRates =
                (from r in fxRateRecordsFiltered
                 let c = r.CurrencyFrom.RoeType == "M" && !r.CurrencyFrom.IsDollar() ? r.CurrencyFrom : r.CurrencyTo
                         select new FxRate
            {
                CurrencyCode = c.CurrencyCode,
                CurrencyRoeType = c.RoeType,
                Date = r.FxRate.ValidDateFrom,
                Rate = r.FxRate.Rate,
                FwdMonth1 = r.FxRate.FwdMonth1,
                FwdMonth2 = r.FxRate.FwdMonth2,
                FwdMonth3 = r.FxRate.FwdMonth3,
                FwdMonth6 = r.FxRate.FwdMonth6,
                FwdYear1 = r.FxRate.FwdYear1,
                FwdYear2 = r.FxRate.FwdYear2,
                CurrencyIsDeactivated = c.IsDeactivated,
                CurrencyDescription = c.Description,
                CreatedBy = r.FxRate.CreatedBy,
                CreatedDateTime = r.FxRate.CreatedDateTime,
                ModifiedBy = r.FxRate.ModifiedBy,
                ModifiedDateTime = r.FxRate.ModifiedDateTime,
                CreationMode = (r.FxRate.CreationModeId == 0) ? string.Empty : ((CreationMode)r.FxRate.CreationModeId).ToString()
            })
                .ToList();

            foreach (var currency in currencies)
            {
                if (fxRates.All(r => r.CurrencyCode != currency.CurrencyCode))
                {
                    fxRates.Add(new FxRate
                    {
                        CurrencyCode          = currency.CurrencyCode,
                        CurrencyRoeType       = currency.RoeType,
                        CurrencyIsDeactivated = currency.IsDeactivated,
                        CurrencyDescription   = currency.Description
                    });
                }
            }

            var result =
                fxRates.OrderBy(r => r.CurrencyCode)
                .Where(r => r.CurrencyCode != "USD")
                .ToList();

            var response = new CollectionViewModel <FxRate>(result);

            return(Ok(response));
        }