2024-06-26 08:04:07 +04:00
|
|
|
using Contracts.ViewModels;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-06-23 16:10:45 +04:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
2024-06-26 08:04:07 +04:00
|
|
|
using System.Diagnostics.Eventing.Reader;
|
|
|
|
using WebApp.Helpers;
|
2024-06-23 16:10:45 +04:00
|
|
|
|
|
|
|
namespace WebApp.Pages
|
|
|
|
{
|
2024-06-26 08:04:07 +04:00
|
|
|
[Authorize(Roles = Roles.User)]
|
2024-06-23 16:10:45 +04:00
|
|
|
public class CartModel : PageModel
|
|
|
|
{
|
2024-06-26 08:04:07 +04:00
|
|
|
public PurchaseViewModel purchaseModel = null;
|
|
|
|
public Dictionary<Guid, int> Products { get; set; }
|
|
|
|
public void OnGet(Guid id, int count)
|
2024-06-23 16:10:45 +04:00
|
|
|
{
|
2024-06-26 08:04:07 +04:00
|
|
|
if (purchaseModel == null)
|
|
|
|
{
|
|
|
|
purchaseModel = APIClient.GetRequest<PurchaseViewModel>($"Purchase/Create/{this.GetUserId()}");
|
2024-06-23 16:10:45 +04:00
|
|
|
|
2024-06-26 08:04:07 +04:00
|
|
|
APIClient.GetRequest<PurchaseViewModel>($"Purchase/AddProducts?purchaseId={purchaseModel.Id}?productId={id}?count={count}");
|
|
|
|
}
|
|
|
|
purchaseModel = APIClient.GetRequest<PurchaseViewModel>($"Purchase/Get/");
|
|
|
|
|
|
|
|
Products = APIClient.GetRequest<Dictionary<Guid, int>>($"Purchase/GetProducts?id={purchaseModel.Id}");
|
|
|
|
}
|
|
|
|
public IActionResult OnPostAsync()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return RedirectToAction("");
|
2024-06-23 16:10:45 +04:00
|
|
|
}
|
|
|
|
}
|
2024-06-26 08:04:07 +04:00
|
|
|
}
|