public async Task <ProductEntity> GetByName(int clientId, string productName) { // TODO: [TESTS] (ProductRepo.GetByName) Add tests return(await GetSingle <ProductEntity>( nameof(GetByName), _queries.GetByName(), new { ClientId = clientId, ProductName = productName } )); }
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> OnPostAddProductAsync() { const string prop = nameof(Category.AddProduct); return(await Category.ProcessAsync(ModelState, nameof(Category), async() => { await _productCommands.AddProductToCategory(Category.Id, Category.AddProduct); return RedirectToPage("./EditCategory", new { id = Category.Id, pageNumber = -1 }); }, async() => { Products = await LoadProductsAsync(Category.Id, Category.PageNumber); return Page(); }, async vrList => { if (Category.AddProduct.IsNullOrEmpty()) { vrList.Add(new ModelValidationResult( prop, "Введите название товара" )); return; } if (Category.AddProduct.Length > 50) { vrList.Add(new ModelValidationResult( prop, "Название товара должно содержать не более 50 символолв" )); return; } var product = await _productQueries.GetByName(Category.AddProduct); if (product != null) { vrList.Add(new ModelValidationResult( prop, "Товар с таким именем уже есть" )); } } )); }
public async Task <IActionResult> OnPostCommitAsync() { return(await Product.ProcessAsync(ModelState, nameof(Product), async() => { await _productCommands.Update(Product.ToModel()); return RedirectToPage("./EditCategory", new { id = Product.CategoryId }); }, async() => await Task.FromResult(Page()), async vrList => { if (!string.IsNullOrEmpty(Product.Name)) { var product = await _productQueries.GetByName(Product.Name); if (product != null && product.Id != Product.Id) { vrList.Add(new ModelValidationResult(nameof(Product.Name), "Товар с таким именем уже есть")); } } } )); }