37 lines
973 B
C#
37 lines
973 B
C#
using MidrandBookshop.Services.ShoppingCart;
|
|
using MidrandBookshop.Services.ShoppingCart.Models;
|
|
|
|
namespace MidrandBookshop.Components.Pages;
|
|
|
|
public partial class Cart(CartService cartService)
|
|
{
|
|
protected Services.ShoppingCart.Models.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();
|
|
}
|
|
}
|