private async Task <IList <string> > ProcessFile(TransactionDataFileModel transactionDataModel) { var transactionFile = transactionDataModel.File; if (transactionFile == null || transactionFile.Length == 0) { throw new InvalidOperationException("File is not selected or is empty"); } var fileReadResult = await FileUtility.ReadFormFileAsync(transactionFile); var errors = await _transactionDataHandler.ParseFileContentAndSaveData(fileReadResult.Content, fileReadResult.FileType); return(errors); }
public async Task <IActionResult> Save(TransactionDataFileModel transactionDataModel) { if (ModelState.IsValid) { var errors = await ProcessFile(transactionDataModel); if (errors.Any()) { var model = new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrorMessage = string.Join('\n', errors) }; return(View("Error", model)); } ViewData["message"] = "File uploaded successfully!"; return(View("Index", new TransactionDataFileModel())); } return(View(nameof(Index), transactionDataModel)); }
public IActionResult Index() { var model = new TransactionDataFileModel(); return(View(model)); }