using LiteCharms.Features.MidrandBooks.AuthorBooks; using LiteCharms.Features.MidrandBooks.Authors; using LiteCharms.Features.MidrandBooks.Payments; using LiteCharms.Features.MidrandBooks.Products; namespace MidrandBookshop.Components; public partial class BookCard { [Parameter] public long Id { get; set; } [Parameter] public string Title { get; set; } = string.Empty; [Parameter] public string Author { get; set; } = string.Empty; [Parameter] public decimal Price { get; set; } [Parameter] public string Category { get; set; } = string.Empty; [Parameter] public bool IsNew { get; set; } [Parameter] public string BookImageUrl { get; set; } = string.Empty; [Parameter] public EventCallback OnCardClick { get; set; } [Inject] private CartService CartService { get; set; } = default!; [Inject] private ProductService ProductService { get; set; } = default!; [Inject] private AuthorService AuthorService { get; set; } = default!; [Inject] private BooksService BooksService { get; set; } = default!; [Inject] private IToastService ToastService { get; set; } = default!; [Inject] private CancellationToken CancellationToken { get; set; } = default!; private async Task HandleAddToCart() { try { var bookFetch = await BooksService.GetBookByProductIdAsync(Id, CancellationToken); var authorFetch = await AuthorService.GetAuthorAsync(bookFetch.Value.AuthorId, CancellationToken); var productPriceFetch = await ProductService.GetProductPriceAsync(Id, CancellationToken); CartService.AddItem(productPriceFetch.Value, bookFetch.Value.Product!, authorFetch.Value); ToastService.ShowSuccess($"Added '{Title}' to your order.", "Cart Changed"); } catch { ToastService.ShowError("Could not update cart. Please try again."); } } }