public async Task <ActionResult> PostMonthlyData(IFormFile salesCSV, IFormFile planCSV, IFormFile fciCSV, string periodId) { //check we have a valid period if (periodId == null || !int.TryParse(periodId, out int pId)) { return(BadRequest()); } //Get the period we are using MLFSReportingPeriod period = await _periodData.GetPeriodById(pId); if (period == null) { return(BadRequest()); } //convert our csvs into datatables string newSalesFilePath = Path.GetTempFileName(); string newPlanFilePath = Path.GetTempFileName(); string newFCIFilePath = Path.GetTempFileName(); if (salesCSV.Length > 0) { using (var fileStream = new FileStream(newSalesFilePath, FileMode.Create)) { await salesCSV.CopyToAsync(fileStream); } } else { return(NotFound()); } if (planCSV.Length > 0) { using (var fileStream = new FileStream(newPlanFilePath, FileMode.Create)) { await planCSV.CopyToAsync(fileStream); } } else { return(NotFound()); } if (fciCSV.Length > 0) { using (var fileStream = new FileStream(newFCIFilePath, FileMode.Create)) { await fciCSV.CopyToAsync(fileStream); } } else { return(NotFound()); } DataTable feeDt = Tools.ConvertCSVToDataTable(newSalesFilePath); DataTable planDt = Tools.ConvertCSVToDataTable(newPlanFilePath); DataTable fciDt = Tools.ConvertCSVToDataTable(newFCIFilePath); //load data to database and get response await _salesData.UploadSalesForPeriod(period, feeDt, planDt); List <MLFSIncome> receipts = await _incomeData.UploadIncomeForPeriod(period, fciDt); await _incomeData.UpdateClientOnboardDate(period); //Allocate Receipts List <MLFSSale> debtors = await _salesData.GetDebtors(); List <MLFSDebtorAdjustment> adjs = MLFSSale.CheckForReceipts(debtors, receipts.Where(x => x.IncomeType.Contains("Initial")).ToList()); _adjData.InsertList(adjs); return(Ok()); }