コード例 #1
0
ファイル: EditIncome.cshtml.cs プロジェクト: lulzzz/Monifier
        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;
                    }
                }
            }
                                             ));
        }