PIAPS_CW/WebApp/Pages/Index.cshtml.cs

26 lines
939 B
C#

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<ProductViewModel, List<MediaFileViewModel>> MediaByProductsModel { get; set; }
public void OnGet()
{
ProductsModel = APIClient.GetRequest<List<ProductViewModel>>($"Product/GetFullList");
MediaByProductsModel = APIClient.GetRequest<Dictionary<ProductViewModel, List<MediaFileViewModel>>>($"MediaFile/GetByProducts?");
}
public List<MediaFileViewModel> GetMediaByProduct(ProductViewModel productModel)
{
MediaByProductsModel.TryGetValue(productModel, out List<MediaFileViewModel> models);
return models;
}
}
}