2024-06-26 08:04:07 +04:00
|
|
|
using Contracts.BindingModels;
|
|
|
|
using Contracts.ViewModels;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
|
|
|
|
namespace WebApp.Pages
|
|
|
|
{
|
|
|
|
public class ProductPageModel : PageModel
|
|
|
|
{
|
|
|
|
public ProductViewModel productModel { get; set; }
|
2024-07-26 02:46:29 +04:00
|
|
|
public SaleViewModel saleModel { get; set; }
|
2024-06-26 08:04:07 +04:00
|
|
|
public MediaFileViewModel mediaFileModel { get; set; }
|
|
|
|
public Dictionary<Guid, List<MediaFileViewModel>> MediaByProductsModel { get; set; }
|
|
|
|
public void OnGet(Guid id)
|
|
|
|
{
|
|
|
|
productModel = APIClient.GetRequest<ProductViewModel>($"Product/GetProduct?id={id}");
|
2024-07-26 02:46:29 +04:00
|
|
|
|
|
|
|
saleModel = APIClient.GetRequest<SaleViewModel>($"Sale/GetSaleByProduct?id={id}");
|
|
|
|
|
2024-06-26 08:04:07 +04:00
|
|
|
}
|
2024-06-28 00:43:29 +04:00
|
|
|
|
2024-06-26 08:04:07 +04:00
|
|
|
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;
|
|
|
|
}
|
2024-06-28 00:43:29 +04:00
|
|
|
|
|
|
|
public List<MediaFileViewModel> GetAllMediaFilesByProduct(ProductViewModel productModel)
|
|
|
|
{
|
|
|
|
MediaByProductsModel = APIClient.GetRequest<Dictionary<Guid, List<MediaFileViewModel>>>($"MediaFile/GetByProducts");
|
|
|
|
MediaByProductsModel.TryGetValue(productModel.Id, out List<MediaFileViewModel> models);
|
|
|
|
return models;
|
|
|
|
}
|
|
|
|
|
2024-07-26 02:46:29 +04:00
|
|
|
public IActionResult OnPostAsync(int count, double price, Guid productId, string productName)
|
2024-06-26 08:04:07 +04:00
|
|
|
{
|
2024-07-26 02:46:29 +04:00
|
|
|
var model = new CartItemBindingModel()
|
2024-06-26 08:04:07 +04:00
|
|
|
{
|
2024-07-26 02:46:29 +04:00
|
|
|
Id = new Guid(),
|
|
|
|
DateCreated = DateTime.Now,
|
|
|
|
ProductId = productId,
|
|
|
|
ProductName = productName,
|
|
|
|
Count = count,
|
|
|
|
UserId = new Guid(this.GetUserId())
|
|
|
|
};
|
|
|
|
APIClient.PostRequest($"CartItem/Create/", model);
|
2024-06-26 08:04:07 +04:00
|
|
|
return RedirectToPage("Cart");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|