public async Task <IActionResult> OnPostAsync() { BalanceState = await _inventorizationQueries.GetBalanceState(); return(await AddCategory.ProcessAsync(ModelState, nameof(AddCategory), async() => { await _categoriesCommands.Update(new CategoryModel { Name = AddCategory.Category }); return RedirectToPage("./Categories", new { pageNumber = -1 }); }, async() => { await LoadCategoriesAsync(AddCategory.PageNumber); return Page(); }, async vrList => { if (!AddCategory.Category.IsNullOrEmpty()) { var category = await _categoriesQueries.GetByName(AddCategory.Category); if (category != null) { vrList.Add(new ModelValidationResult(nameof(AddCategory.Category), "Категория товаров с таким именем уже есть")); } } })); }
private async Task <ExpenseItemModel> GetExpenseItem() { var item = Good.ToItemModel(); var category = string.IsNullOrEmpty(Good.Category) ? null : await _categoriesQueries.GetByName(Good.Category); item.CategoryId = category?.Id; var product = string.IsNullOrEmpty(Good.Product) ? null : await _productQueries.GetByName(Good.Product); item.ProductId = product?.Id; return(item); }
public async Task <IActionResult> OnPostEditAsync() { return(await Category.ProcessAsync(ModelState, nameof(Category), async() => { var category = await _categoriesQueries.GetByName(Category.Category); if (category == null) { await _categoriesCommands.Update(new CategoryModel { Id = Category.Id, Name = Category.Category }); } return RedirectToPage("./Categories", new { pageNumber = 1 }); }, async() => { Products = await LoadProductsAsync(Category.Id, Category.PageNumber); return Page(); })); }