public async Task<IActionResult> Create(AccountStatementViewModel model) { if (ModelState.IsValid) { IFileUpload upload; try { upload = await context.SaveFileUploadAsync(model.Attachment); } catch (Exception ex) { throw new Exception("Failed to save uploaded file. Please upload it again later.", ex); } var statement = new AccountStatement { BankAccountId = model.BankAccountId.Value, FileUploadId = upload.Id, ProcessedAt = DateTimeOffset.Now }; context.AccountStatements.Add(statement); await context.SaveChangesAsync(); statementProcessor.StartProcessing(statement.Id); return RedirectToAction("Index"); } ViewData["BankAccountId"] = new SelectList(context.BankAccounts, "Id", "Name", model.BankAccountId); return View(model); }
// GET: AccountStatements/Create public IActionResult Create(int? accountId = null) { var viewModel = new AccountStatementViewModel { BankAccountId = accountId }; ViewData["BankAccountId"] = new SelectList(context.BankAccounts, "Id", "Name"); return View(viewModel); }