ShopOnlineSolution/ShopOnline.Web/Pages/ProductDetailsBase.cs

30 lines
762 B
C#

using Microsoft.AspNetCore.Components;
using ShopOnline.Models.Dtos;
using ShopOnline.Web.Services.Contracts;
using System.Xml.Serialization;
namespace ShopOnline.Web.Pages
{
public class ProductDetailsBase : ComponentBase
{
[Parameter]
public int Id { get; set; }
[Inject]
public IProductService ProductService { get; set; }
public ProductDto Product { get; set; }
public string ErrorMessage { get; set; }
protected override async Task OnInitializedAsync()
{
try
{
Product = await ProductService.GetItem(Id);
}
catch(Exception ex)
{
ErrorMessage = ex.Message;
}
}
}
}