44 lines
1.8 KiB
C#
44 lines
1.8 KiB
C#
using Contracts.BindingModels;
|
|
using Contracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace WebApp.Pages
|
|
{
|
|
public class ProductPageModel : PageModel
|
|
{
|
|
public PurchaseViewModel purchaseModel { get; set; }
|
|
public ProductViewModel productModel { get; set; }
|
|
public MediaFileViewModel mediaFileModel { get; set; }
|
|
public Dictionary<Guid, List<MediaFileViewModel>> MediaByProductsModel { get; set; }
|
|
public int Amount { get; set; } // Ñâîéñòâî äëÿ õðàíåíèÿ êîëè÷åñòâà òîâàðà
|
|
public void OnGet(Guid id)
|
|
{
|
|
productModel = APIClient.GetRequest<ProductViewModel>($"Product/GetProduct?id={id}");
|
|
}
|
|
public byte[] GetMediaByProduct(ProductViewModel productModel)
|
|
{
|
|
MediaByProductsModel = APIClient.GetRequest<Dictionary<Guid, List<MediaFileViewModel>>>($"MediaFile/GetByProducts");
|
|
MediaByProductsModel.TryGetValue(productModel.Id, out List<MediaFileViewModel> models);
|
|
return models[0].Image;
|
|
}
|
|
public IActionResult OnPostAsync(Guid id, int count)
|
|
{
|
|
Amount = count;
|
|
if (purchaseModel == null)
|
|
{
|
|
var model = new PurchaseBindingModel()
|
|
{
|
|
Cost = 0,
|
|
DatePurchase = DateTime.Now,
|
|
Status = 0,
|
|
UserId = new Guid(this.GetUserId())
|
|
};
|
|
//purchaseModel = APIClient.PostRequest<PurchaseBindingModel>($"Purchase/Create", model);
|
|
}
|
|
APIClient.GetRequest<PurchaseViewModel>($"Purchase/AddProducts?purchaseId={purchaseModel.Id}?productId={id}?count={count}");
|
|
return RedirectToPage("Cart");
|
|
}
|
|
}
|
|
}
|