PIAPS_CW/WebApp/Pages/Index.cshtml.cs
2024-06-26 08:04:07 +04:00

37 lines
1.3 KiB
C#

using Contracts.SearchModels;
using Contracts.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{
[AllowAnonymous]
public class IndexModel : PageModel
{
public List<ProductViewModel> ProductsModel { get; set; }
public Dictionary<Guid, List<MediaFileViewModel>> MediaByProductsModel { get; set; }
public void OnGet(double? pricefrom, double? priceto, string? search)
{
string request = "Product/GetList";
if (!string.IsNullOrEmpty(search))
request += $"?search={search}";
if (pricefrom != null)
request += $"?pricefrom={pricefrom}";
if (priceto != null)
request += $"?priceto={priceto}";
ProductsModel = APIClient.GetRequest<List<ProductViewModel>>(request);
MediaByProductsModel = APIClient.GetRequest<Dictionary<Guid, List<MediaFileViewModel>>>($"MediaFile/GetByProducts");
}
public byte[] GetMediaByProduct(ProductViewModel productModel)
{
MediaByProductsModel.TryGetValue(productModel.Id, out List<MediaFileViewModel> models);
return models[0].Image;
}
}
}