Это код: < /p>
Код: Выделить всё
@page "/categorie"
@using MyOnlineShop.Components.Controls
@using MyOnlineShop.Controllers
@using MyOnlineShop.Models
@inject IProductCategoriesController CategoriesController
@inject NavigationManager NavigationManager
Categorie
@if (@createFields)
{
Nascondi
}
else
{
Crea
}
@if (@createFields)
{
Aggiungi categoria
Categoria:
Descrizione categoria:
Note:
Salva
}
@if (filteredProductCategoriesList != null)
{
@searchMessage
Nome categoria
Descrizione
Note
@foreach (var productCategory in filteredProductCategoriesList)
{
@if (editingId == productCategory.ProductCategoryId)
{
@*
@modifyProductCategory.ProductCategoryName
*@
@*
@modifyProductCategory.ProductCategoryDescription
*@
@*
@modifyProductCategory.ProductCategoryNote
*@
Salva
Annulla
}
else
{
@productCategory.ProductCategoryName
@productCategory.ProductCategoryDescription
@productCategory.ProductCategoryNote
Modifica
Elimina
}
}
}
@code {
public bool createFields = false;
public bool modifyField = false;
private string searchMessage = "";
private int? editingId = null;
[SupplyParameterFromForm(FormName = "CreateProductCategoriesForm")]
public ProductCategory? createProductCategory { get; set; } = new ProductCategory();
[SupplyParameterFromForm(FormName = "ModifyProductCategoriesForm")]
private ProductCategory? modifyProductCategory { get; set; }
private List
? productCategoriesList;
private List? filteredProductCategoriesList;
public void ShowCreateFields()
{
if (createFields)
{
Console.WriteLine("Not Showing");
createFields = false;
}
else
{
Console.WriteLine("Showing");
createFields = true;
}
}
protected override void OnParametersSet()
{
productCategoriesList = CategoriesController.GetProductCategories();
filteredProductCategoriesList = productCategoriesList;
}
private void CreateProductCategory()
{
Console.WriteLine("Submitted categoria articoli");
if (createProductCategory != null)
{
CategoriesController.CreateProductCategory(createProductCategory);
NavigationManager.Refresh(forceReload: true);
}
}
private void DeleteProductCategory(int productCategoryId)
{
CategoriesController.DeleteProductCategory(productCategoryId);
NavigationManager.Refresh(forceReload: true);
}
private void StartEdit(ProductCategory productCategory)
{
editingId = productCategory.ProductCategoryId;
modifyProductCategory = new ProductCategory
{
ProductCategoryName = productCategory.ProductCategoryName,
ProductCategoryDescription = productCategory.ProductCategoryDescription,
ProductCategoryNote = productCategory.ProductCategoryNote
};
}
private void SaveEdit()
{
if (modifyProductCategory != null)
CategoriesController.ModifyProductCategory(modifyProductCategory.ProductCategoryId, modifyProductCategory);
CancelEdit();
}
private void CancelEdit()
{
editingId = null;
modifyProductCategory = new ProductCategory();
}
private void HandleSearch(string searchFilterString)
{
filteredProductCategoriesList = productCategoriesList;
if (filteredProductCategoriesList != null)
{
filteredProductCategoriesList = productCategoriesList.Where(x => x.ProductCategoryDescription.ToLower().Trim().Contains(searchFilterString.ToLower().Trim())).ToList();
searchMessage = "";
if (filteredProductCategoriesList.Count()
Подробнее здесь: [url]https://stackoverflow.com/questions/79669774/add-two-editform-on-a-blazor-page[/url]