private async Task <string> GetAvailableBalanceAsync() { const string unknownBalance = "-"; if (string.IsNullOrEmpty(Transfer?.AccountFrom)) { return(unknownBalance); } var account = await _accountQueries.GetByName(Transfer.AccountFrom); return(account == null ? unknownBalance : account.AvailBalance.ToMoney()); }
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; } } } )); }
public async Task <IActionResult> OnPostAsync() { Accounts = await _accountQueries.GetAll(); return(await Transfer.ProcessAsync(ModelState, nameof(Transfer), async() => { var accountFrom = await _accountQueries.GetByName(Transfer.AccountFrom); var accountTo = await _accountQueries.GetByName(Transfer.AccountTo); await _accountCommands.Transfer(accountFrom.Id, accountTo.Id, Transfer.Amount.ParseMoneyInvariant()); return RedirectToPage("./AccountsList"); }, async() => { var account = await _accountQueries.GetByName(Transfer.AccountFrom); AvailableBalance = account != null ? account.Balance.ToMoney() : "-"; return Page(); }, async vrList => { if (!Transfer.AccountFrom.IsNullOrEmpty()) { var accountFrom = await _accountQueries.GetByName(Transfer.AccountFrom); if (accountFrom == null) { vrList.Add(new ModelValidationResult(nameof(Transfer.AccountFrom), "Такого счета нет")); } } if (!Transfer.AccountTo.IsNullOrEmpty()) { var accountTo = await _accountQueries.GetByName(Transfer.AccountTo); if (accountTo == null) { vrList.Add(new ModelValidationResult(nameof(Transfer.AccountTo), "Такого счета нет")); } } })); }
public async Task <IActionResult> OnPostAsync() { return(await Expense.ProcessAsync(ModelState, nameof(Expense), async() => { await _expenseFlowCommands.AddExpense(Expense.ToModel()); return RedirectToPage(Expense.ReturnPage); }, async() => { await PrepareModels(Expense.FlowId); return Page(); }, async vrList => { if (!Expense.Account.IsNullOrEmpty()) { var account = await _accountQueries.GetByName(Expense.Account); if (account == null) { vrList.Add(new ModelValidationResult(nameof(Expense.Account), "Нет такого счета")); } } if (!Expense.FlowName.IsNullOrEmpty()) { var flow = await _expenseFlowQueries.GetByName(Expense.FlowName); if (flow == null) { vrList.Add(new ModelValidationResult(nameof(Expense.FlowName), "Нет такой статьи расхода")); } else { Expense.FlowId = flow.Id; } } CategoryModel category = null; if (!string.IsNullOrEmpty(Expense.Category)) { category = await _categoriesQueries.GetFlowCategoryByName(Expense.FlowId, Expense.Category); if (category == null) { if (Expense.Category == Expense.CategoryToAdd) { category = await _categoriesCommands.CreateNewOrBind( Expense.FlowId, Expense.Category); Expense.CategoryToAdd = null; } else { vrList.Add(new ModelValidationResult(nameof(Expense.Category), "Нет такой категории, добавить ее?")); Expense.CategoryToAdd = Expense.Category; } } } if (!string.IsNullOrEmpty(Expense.Product)) { var product = await _productQueries.GetFlowProductByName(Expense.FlowId, Expense.Product); if (product == null) { if (Expense.Product == Expense.ProductToAdd && category != null) { await _productCommands.AddProductToCategory(category.Id, Expense.Product); Expense.ProductToAdd = null; } else { vrList.Add(new ModelValidationResult(nameof(Expense.Product), "Нет такого товара, добавить его?")); Expense.ProductToAdd = Expense.Product; } } } })); }
public async Task <IActionResult> OnPostAddAsync() { return(await Good.ProcessAsync(ModelState, nameof(Good), async() => { await PrepareModelsAsync(Good.FlowId); Bill = JsonConvert.DeserializeObject <ExpenseBillModel>(Good.Bill); Bill.AddItem(await GetExpenseItem()); Good.ClearInput(); Good.Bill = JsonConvert.SerializeObject(Bill); return Page(); }, async() => { await PrepareModelsAsync(Good.FlowId); Bill = JsonConvert.DeserializeObject <ExpenseBillModel>(Good.Bill); return Page(); }, async vrList => { if (Good.Account.IsNullOrEmpty()) { vrList.Add(new ModelValidationResult(nameof(Good.Account), "Укажите счет")); } else { var account = await _accountQueries.GetByName(Good.Account); if (account == null) { vrList.Add(new ModelValidationResult(nameof(Good.Account), "Нет такого счета")); } } if (Good.FlowName.IsNullOrEmpty()) { vrList.Add(new ModelValidationResult(nameof(Good.FlowName), "Укажите статью расходов")); return; } var flowId = await _expenseFlowQueries.GetIdByName(Good.FlowName); if (flowId == null) { vrList.Add(new ModelValidationResult(nameof(Good.FlowName), "Нет такой статьи расходов")); return; } Good.FlowId = flowId.Value; CategoryModel category = null; if (!Good.Category.IsNullOrEmpty()) { category = await _categoriesQueries.GetFlowCategoryByName(Good.FlowId, Good.Category); if (category == null) { if (Good.Category == Good.CategoryToAdd) { category = await _categoriesCommands.CreateNewOrBind(Good.FlowId, Good.Category); Good.CategoryToAdd = null; } else { vrList.Add(new ModelValidationResult(nameof(Good.Category), "Нет такой категории, добавить ее?")); Good.CategoryToAdd = Good.Category; } } } if (!Good.Product.IsNullOrEmpty()) { var product = await _productQueries.GetFlowProductByName(Good.FlowId, Good.Product); if (product == null) { if (Good.Product == Good.ProductToAdd && category != null) { await _productCommands.AddProductToCategory(category.Id, Good.Product); Good.ProductToAdd = null; } else { vrList.Add(new ModelValidationResult(nameof(Good.Product), "Нет такого товара, добавить его?")); Good.ProductToAdd = Good.Product; } } } })); }