66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using ShopOnline.Models.Dtos;
|
|
using ShopOnline.Web.Services.Contracts;
|
|
|
|
namespace ShopOnline.Web.Pages
|
|
{
|
|
public class CheckoutBase:ComponentBase
|
|
{
|
|
[Inject]
|
|
public IJSRuntime Js { get; set; }
|
|
|
|
protected IEnumerable<CartItemDto> ShoppingCartItems { get; set; }
|
|
|
|
protected int TotalQuantity { get; set; }
|
|
|
|
protected string PaymentDescription { get; set; }
|
|
|
|
protected decimal PaymentAmount { get; set; }
|
|
|
|
[Inject]
|
|
public IShoppingCartService ShoppingCartService { get; set; }
|
|
|
|
[Inject]
|
|
public IManageCartItemsLocalStorageService ManageCartItemsLocalStorage { get; set; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
ShoppingCartItems = await ManageCartItemsLocalStorage.GetCollection();
|
|
|
|
if(ShoppingCartItems != null)
|
|
{
|
|
Guid orderGuid = Guid.NewGuid();
|
|
|
|
PaymentAmount = ShoppingCartItems.Sum(p => p.TotalPrice);
|
|
TotalQuantity = ShoppingCartItems.Sum(p => p.Quantity);
|
|
PaymentDescription = $"O_{HardCoded.UserId}_{orderGuid}";
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
try
|
|
{
|
|
if(firstRender)
|
|
{
|
|
await Js.InvokeVoidAsync("initPayPalButton");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|