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; } public SaleViewModel saleModel { get; set; } public MediaFileViewModel mediaFileModel { get; set; } public Dictionary> MediaByProductsModel { get; set; } public void OnGet(Guid id) { productModel = APIClient.GetRequest($"Product/GetProduct?id={id}"); saleModel = APIClient.GetRequest($"Sale/GetSaleByProduct?id={id}"); } public byte[] GetMediaByProduct(ProductViewModel productModel) { MediaByProductsModel = APIClient.GetRequest>>($"MediaFile/GetByProducts"); MediaByProductsModel.TryGetValue(productModel.Id, out List models); return models[0].Image; } public List GetAllMediaFilesByProduct(ProductViewModel productModel) { MediaByProductsModel = APIClient.GetRequest>>($"MediaFile/GetByProducts"); MediaByProductsModel.TryGetValue(productModel.Id, out List models); return models; } public IActionResult OnPostAsync(int count, double price, Guid productId, string productName) { var model = new CartItemBindingModel() { Id = new Guid(), DateCreated = DateTime.Now, ProductId = productId, ProductName = productName, Count = count, UserId = new Guid(this.GetUserId()) }; APIClient.PostRequest($"CartItem/Create/", model); return RedirectToPage("Cart"); } } }