public async Task <IActionResult> ImageList(IFormCollection file_collection) { if (file_collection["formChoice"].Equals(StringValues.Empty)) { return(Json(new { response = "invalid form type" })); } AbstractFormObject.FormType formType = (AbstractFormObject.FormType)Enum.Parse(typeof(AbstractFormObject.FormType), file_collection["formChoice"].ToString()); return(await PostImage(file_collection.Files.ToList(), formType)); }
public static PWAsubmission FromForm(AbstractFormObject form, AbstractFormObject.FormType formType) { PWAsubmission submission; switch (formType) { case AbstractFormObject.FormType.OR526_ATTENDANT: case AbstractFormObject.FormType.OR507_RELIEF: submission = new PWATimesheet(); break; case AbstractFormObject.FormType.OR004_MILEAGE: submission = new PWAMileage(); break; default: throw new ArgumentException(); } submission.approval = new PWAsubmissionVals(form.approval.ToString()); submission.authorization = new PWAsubmissionVals(form.authorization.ToString()); submission.brokerage = new PWAsubmissionVals(form.brokerage); submission.clientName = new PWAsubmissionVals(form.clientName); submission.employerSignature = new PWAsubmissionVals(form.employerSignature.ToString()); submission.employerSignDate = new PWAsubmissionVals(form.employerSignDate); submission.id = form.id; submission.prime = new PWAsubmissionVals(form.prime); submission.progressNotes = new PWAsubmissionVals(form.progressNotes); submission.providerName = new PWAsubmissionVals(form.providerName); submission.providerNum = new PWAsubmissionVals(form.providerNum); submission.providerSignature = new PWAsubmissionVals(form.employerSignature.ToString()); submission.providerSignDate = new PWAsubmissionVals(form.employerSignDate); submission.scpaName = new PWAsubmissionVals(form.scpaName); submission.serviceAuthorized = new PWAsubmissionVals(form.serviceAuthorized); submission.serviceGoal = new PWAsubmissionVals(form.serviceGoal); submission.ConvertForm(form); return(submission); }
public async Task <IActionResult> PostImage(List <IFormFile> files, AbstractFormObject.FormType formType) { var c = files.Count; var image_responses = new List <AnalyzeDocumentResponse>(); var pdf_responses = new List <GetDocumentAnalysisResponse>(); var skipped_files = new List <string>(); var stats = new List <string>(); // MIME types we can send to textract var accepted_types = new List <string> { "image/jpeg", "image/png", "application/pdf", }; // Iterate of collection of file and send to Textract foreach (var file in files) { // Nothing to work with, next! if (file.Length == 0) { skipped_files.Add("File name " + file.Name + " is empty"); continue; } // Only process files that have acceptable types if (accepted_types.Contains(file.ContentType)) { //Time how long it takes Textract to process image Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // Process PDF if (file.ContentType == "application/pdf") { pdf_responses.Add(process_pdf(file)); } // Process image else { image_responses.Add(process_image(file)); } stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; string s = String.Format("{0:00}:{1:00}", ts.Minutes, ts.Seconds); stopwatch.Reset(); stats.Add(file.FileName + " " + s); } else { skipped_files.Add( "File name " + file.Name + " has incompatible type " + file.ContentType ); } } int stageId; if (pdf_responses.Count > 0) { stageId = await saveSubmissionStage(await UploadToBlob(files), pdf_responses, formType); } else { stageId = await saveSubmissionStage(await UploadToBlob(files), image_responses, formType); } return(Json(new { file_count = c, skipped = skipped_files, id = stageId } )); }
private async Task <int> saveSubmissionStage <T>(string uriString, List <T> responses, AbstractFormObject.FormType formType) { // Create a SubmissionStaging to upload to SubmissionStaging table var ss = new SubmissionStaging { ParsedTextractJSON = System.Text.Json.JsonSerializer.Serialize(responses), UriString = uriString, formType = formType }; // Add SubmissionStaging to table and get the Id to add to JSON response return _context.Add(ss); await _context.SaveChangesAsync(); return(ss.Id); }