public async Task <IActionResult> OnPostAsync() { return(await Topup.ProcessAsync(ModelState, nameof(Topup), async() => { var incomeType = await _incomeTypeQueries.GetByName(Topup.IncomeType); var account = await _accountQueries.GetByName(Topup.AccountName); await _accountCommands.Topup(new BusinessLogic.Model.Accounts.TopupAccountModel { Correction = Topup.Correcting, AccountId = account.Id, IncomeTypeId = incomeType?.Id, AddIncomeTypeName = incomeType == null ? Topup.IncomeType : null, TopupDate = Topup.TopupDate.ParseDtFromStandardString(), Amount = Topup.Amount.ParseMoneyInvariant() }); return RedirectToPage(Topup.ReturnPage); }, async() => { IncomeTypes = await _incomeTypeQueries.GetAll(); Accounts = await _accountQueries.GetAll(); return Page(); }, async vrList => { if (!Topup.AccountName.IsNullOrEmpty()) { var account = await _accountQueries.GetByName(Topup.AccountName); if (account == null) { vrList.Add(new ModelValidationResult(nameof(Topup.AccountName), "Нет такого счета")); } } if (!Topup.IncomeType.IsNullOrEmpty()) { var incomeType = await _incomeTypeQueries.GetByName(Topup.IncomeType); if (incomeType == null && !Topup.AddNonexistentIncomeType) { vrList.Add(new ModelValidationResult(nameof(Topup.IncomeType), "Нет такой статьи")); SuggestAddIncomeType = true; Topup.AddNonexistentIncomeType = true; } } })); }
public async Task <IActionResult> OnPostAsync() { return(await Income.ProcessAsync(ModelState, nameof(Income), async() => { var model = Income.ToItemModel(); await _incomeItemCommands.Update(model); return RedirectToPage("./IncomesTable"); }, async() => { await PrepareModelsAsync(); return Page(); }, async vrList => { if (!Income.Account.IsNullOrEmpty()) { var account = await _accountQueries.GetByName(Income.Account); if (account == null) { vrList.Add(new ModelValidationResult(nameof(Income.Account), "Нет такого счета")); } else { Income.AccountId = account.Id; } } if (!Income.IncomeType.IsNullOrEmpty()) { var incomeType = await _incomeTypeQueries.GetByName(Income.IncomeType); if (incomeType == null) { vrList.Add(new ModelValidationResult(nameof(Income.IncomeType), "Нет такой статьи дохода")); } else { Income.IncomeTypeId = incomeType.Id; } } } )); }