public async Task <ActionResult <ValidatedFxRateManualImport> > FileUpload([FromForm, Required] IFormFile file) { var lines = new List <string>(); using (var reader = new StreamReader(file.OpenReadStream())) { while (reader.Peek() >= 0) { lines.Add(await reader.ReadLineAsync()); } } var dataReadFromCsv = lines .Skip(1) .Select((l, i) => FxRateCsvLine.ParseFromCsv(l, i)) .ToList(); var fxRateImporter = new FxRatesCsvImporter(_fxRateRepository, _currencyRepository); var validatedResult = await fxRateImporter.ProcessManualFxRatesImport(dataReadFromCsv); return(Ok(validatedResult)); }
private static bool ValidateExistingDate(List <FxRateValidationError> validationErrors, FxRateCsvLine csvLine, IEnumerable <FxRateRecord> existingFxRateRecords) { if (existingFxRateRecords.ToList().Any(existingFxrate => existingFxrate.ValidDateFrom == Convert.ToDateTime(DateTime.ParseExact(csvLine.Date, "yyyyMMdd", CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")))) { validationErrors.Add(new FxRateValidationError(csvLine, "WARNING_EXISTINGDATE")); return(false); } return(true); }
private static bool ValidateDate(List <FxRateValidationError> validationErrors, FxRateCsvLine csvLine) { if (!DateTime.TryParseExact(csvLine.Date, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime result) || result > DateTime.Today) { validationErrors.Add(new FxRateValidationError(csvLine, "INVALID_DATE")); return(false); } return(true); }
private static bool ValidateFwdPoints(List <FxRateValidationError> validationErrors, FxRateCsvLine csvLine) { bool Check(string fwdMonthString, string errorType) { if (!decimal.TryParse(fwdMonthString, out decimal fwdMonth) || BitConverter.GetBytes(decimal.GetBits(decimal.Parse(fwdMonthString, CultureInfo.InvariantCulture))[3])[2] > 10) { validationErrors.Add(new FxRateValidationError(csvLine, errorType)); return(false); } return(true); } return(Check(csvLine.FwdMonth1, "INVALID_FWDMTH1") && Check(csvLine.FwdMonth2, "INVALID_FWDMTH2") && Check(csvLine.FwdMonth3, "INVALID_FWDMTH3") && Check(csvLine.FwdMonth6, "INVALID_FWDMTH6") && Check(csvLine.FwdYear1, "INVALID_FWDYR1") && Check(csvLine.FwdYear2, "INVALID_FWDYR2")); }
private static bool ValidateRate(List <FxRateValidationError> validationErrors, FxRateCsvLine csvLine) { if (!decimal.TryParse(csvLine.Rate, NumberStyles.Number, CultureInfo.InvariantCulture, out decimal rate) || rate <= 0 || BitConverter.GetBytes(decimal.GetBits(rate)[3])[2] > 10) { validationErrors.Add(new FxRateValidationError(csvLine, "INVALID_RATE")); return(false); } return(true); }
private static bool ValidateRoeType(List <FxRateValidationError> validationErrors, FxRateCsvLine csvLine, IEnumerable <Currency> currencies) { if (currencies.Any(currency => csvLine.CurrencyCode == currency.CurrencyCode && csvLine.RoeType != currency.RoeType)) { validationErrors.Add(new FxRateValidationError(csvLine, "INVALID_ROETYPE")); return(false); } return(true); }
private static bool ValidateActiveCurrency(List <FxRateValidationError> validationErrors, FxRateCsvLine csvLine, IEnumerable <Currency> currencies) { if (currencies.Where(c => c.IsDeactivated).Any(currency => currency.CurrencyCode == csvLine.CurrencyCode)) { validationErrors.Add(new FxRateValidationError(csvLine, "WARNING_INACTIVE_CURRENCY")); return(false); } return(true); }
private static bool ValidateCurrency(List <FxRateValidationError> validationErrors, FxRateCsvLine csvLine, IEnumerable <Currency> currencies) { if (!currencies.Any(currency => currency.CurrencyCode == csvLine.CurrencyCode)) { validationErrors.Add(new FxRateValidationError(csvLine, "INVALID_CURRENCY")); return(false); } return(true); }
public FxRateValidationError(FxRateCsvLine csvLine, string errorCode) { FxRateCsvLine = csvLine; ErrorCode = errorCode; }