41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using LiteCharms.Features.MidrandBooks.Payments;
|
|
using LiteCharms.Features.MidrandBooks.Payments.Models;
|
|
|
|
namespace MidrandBookshop.Components.Pages;
|
|
|
|
public partial class CartReview(CartService cartService)
|
|
{
|
|
[Inject] public IToastService ToastService { get; set; } = default!;
|
|
|
|
protected Cart ShoppingCart => cartService?.ShoppingCart!;
|
|
|
|
protected async void IncreaseQty(CartItem item)
|
|
{
|
|
if (item is not null)
|
|
{
|
|
cartService.UpdateQuantity(item!.Price!.Id, 1);
|
|
|
|
await cartService.SaveCartToStorageAsync();
|
|
}
|
|
}
|
|
protected async void DecreaseQty(CartItem item, int delta)
|
|
{
|
|
var peekQuantity = item.Quantity + delta;
|
|
|
|
if (peekQuantity < 1) return;
|
|
|
|
cartService.UpdateQuantity(item!.Price!.Id, delta);
|
|
|
|
await cartService.SaveCartToStorageAsync();
|
|
}
|
|
|
|
private async void RemoveFromCart(CartItem item)
|
|
{
|
|
cartService.RemoveOneItem(item.Price!.Id);
|
|
|
|
await cartService.SaveCartToStorageAsync();
|
|
|
|
ToastService.ShowSuccess($"Removed {item.Product!.Name} from cart", "Cart Changed");
|
|
}
|
|
}
|