public async Task <IncomeItemModel> Topup(TopupAccountModel topup) { var account = await _repository.LoadAsync <Account>(topup.AccountId).ConfigureAwait(false); var incomeTypeId = topup.IncomeTypeId; if (incomeTypeId == null) { var incomeType = new IncomeType { Name = topup.AddIncomeTypeName, OwnerId = _currentSession.UserId }; _repository.Create(incomeType); await _repository.SaveChangesAsync().ConfigureAwait(false); incomeTypeId = incomeType.Id; } var income = new IncomeItemModel { AccountId = account.Id, DateTime = topup.TopupDate, IncomeTypeId = incomeTypeId.Value, Total = topup.Amount, IsCorrection = topup.Correction, }; await _incomeItemCommands.Update(income).ConfigureAwait(false); await _repository.SaveChangesAsync().ConfigureAwait(false); return(income); }
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; } } } )); }