public async Task <IActionResult> UploadBatches(string textfromAllfiles) { List <BatchReport> batchReports = _batchDataFileManager.ProcessStringIntoBatchReports(textfromAllfiles); int goodBatches = 0; int badBatches = 0; await CheckForbatchesThatAlreadyExist(batchReports); foreach (var report in batchReports) { if (report.IsValidBatch) { goodBatches++; issueScannerManager.ScanForIssues(report); _batchRepository.Add(report); } else { badBatches++; _batchRepository.AddConversionFaults(report.ConversionFaults); } } _batchRepository.SaveChanges(); _shiftLogRepository.AddBatchesToShiftLog(batchReports); ViewData["goodBatches"] = goodBatches; ViewData["badBatches"] = badBatches; ViewData["totalBatches"] = batchReports.Count; return(View("ViewResults", batchReports)); }
public ActionResult <BatchReport> AddBatchToDatabase([FromBody] BatchReport batch) { var request = Request; var headers = request.Headers; var isSync = Convert.ToBoolean(headers["Sync"]); if (batch == null) { return(NotFound()); } if (headers.ContainsKey("Authorization")) { // The authorization key will be the computers MAC address when software goes live // it was set to this for testing purposes if (headers["Authorization"] == "Auth 123456") { if (batch.IsValidBatch) { issueScannerManager.ScanForIssues(batch); var batchReport = _apiBatchRepository.AddBatchToDb(batch); if (!isSync) { var batchJson = JsonConvert.SerializeObject(batchReport); batchJson = AddAdditionalInfoToJson(batchJson, batch, isSync); var batchesMadeJson = JsonConvert.SerializeObject(BatchesMadePerWeekByCategory()); _hubContext.Clients.All.SendAsync("LastBatch", batchJson); _hubContext.Clients.All.SendAsync("BatchesMadeByCategory", batchesMadeJson); } } else { return(BadRequest()); } } else { return(Unauthorized()); } } else { return(Unauthorized()); } return(Ok()); }