PIAPS_CW/WebApp/Pages/Index.cshtml.cs

43 lines
1.5 KiB
C#
Raw Normal View History

2024-06-25 20:26:34 +04:00
using Contracts.SearchModels;
2024-06-25 15:03:16 +04:00
using Contracts.ViewModels;
using Microsoft.AspNetCore.Authorization;
2024-05-09 17:45:03 +04:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{
2024-06-25 15:03:16 +04:00
[AllowAnonymous]
2024-05-09 17:45:03 +04:00
public class IndexModel : PageModel
{
2024-06-25 15:03:16 +04:00
public List<ProductViewModel> ProductsModel { get; set; }
public List<SaleViewModel> SalesModel { get; set; }
2024-06-25 20:26:34 +04:00
public Dictionary<Guid, List<MediaFileViewModel>> MediaByProductsModel { get; set; }
2024-05-09 17:45:03 +04:00
public void OnGet(double? pricefrom, double? priceto, string? search, string? category)
2024-05-09 17:45:03 +04:00
{
2024-06-25 20:26:34 +04:00
string request = "Product/GetList";
if (!string.IsNullOrEmpty(search))
request += $"?search={search}&";
if (!string.IsNullOrEmpty(category))
request += $"?category={category}&";
2024-06-25 20:26:34 +04:00
if (pricefrom != null)
request += $"?pricefrom={pricefrom}&";
2024-06-25 20:26:34 +04:00
if (priceto != null)
request += $"?priceto={priceto}";
ProductsModel = APIClient.GetRequest<List<ProductViewModel>>(request);
2024-06-26 08:04:07 +04:00
MediaByProductsModel = APIClient.GetRequest<Dictionary<Guid, List<MediaFileViewModel>>>($"MediaFile/GetByProducts");
SalesModel = APIClient.GetRequest<List<SaleViewModel>>($"Sale/GetList");
}
2024-06-25 20:26:34 +04:00
public byte[] GetMediaByProduct(ProductViewModel productModel)
{
2024-06-25 20:26:34 +04:00
MediaByProductsModel.TryGetValue(productModel.Id, out List<MediaFileViewModel> models);
return models[0].Image;
2024-05-09 17:45:03 +04:00
}
}
}