diff --git a/RestAPI/Controllers/CartController.cs b/RestAPI/Controllers/CartController.cs deleted file mode 100644 index 3103495..0000000 --- a/RestAPI/Controllers/CartController.cs +++ /dev/null @@ -1,83 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; - -namespace RestAPI.Controllers -{ - public class CartController : Controller - { - // GET: CartController - public ActionResult Index() - { - return View(); - } - - // GET: CartController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: CartController/Create - public ActionResult Create() - { - return View(); - } - - // POST: CartController/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: CartController/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } - - // POST: CartController/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: CartController/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: CartController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - } -} diff --git a/RestAPI/Controllers/MediaFileController.cs b/RestAPI/Controllers/MediaFileController.cs new file mode 100644 index 0000000..1168022 --- /dev/null +++ b/RestAPI/Controllers/MediaFileController.cs @@ -0,0 +1,60 @@ +using Contracts.BusinessLogicContracts; +using Contracts.SearchModels; +using Contracts.ViewModels; +using DatabaseImplement.Models; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; + +namespace RestAPI.Controllers +{ + public class MediaFileController : Controller + { + private readonly IMediaFileLogic _mediaFileLogic; + private readonly IProductLogic _productLogic; + private readonly ILogger _logger; + public MediaFileController(ILogger logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic) + { + _logger = logger; + _mediaFileLogic = mediaFileLogic; + _productLogic = productLogic; + } + [HttpGet] + public List GetFullList() + { + try + { + return _mediaFileLogic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } + [HttpGet] + public Dictionary> GetByProducts() + { + try + { + var dict = new Dictionary>(); + var products = _productLogic.ReadList(null); + + foreach (var product in products) + { + var media = _mediaFileLogic.ReadList(new MediaFileSearchModel() + { + ProductId = product.Id, + }); + dict.Add(product, media); + } + return dict; + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } + } +} diff --git a/WebApp/Pages/Index.cshtml b/WebApp/Pages/Index.cshtml index d4eec0d..4c98134 100644 --- a/WebApp/Pages/Index.cshtml +++ b/WebApp/Pages/Index.cshtml @@ -48,7 +48,7 @@ @foreach (var weapon in @Model.ProductsModel) {
- @weapon.Name + @weapon.Name
@weapon.Name

Цена: >@weapon.Price руб.

diff --git a/WebApp/Pages/Index.cshtml.cs b/WebApp/Pages/Index.cshtml.cs index 0dadbf9..644a6de 100644 --- a/WebApp/Pages/Index.cshtml.cs +++ b/WebApp/Pages/Index.cshtml.cs @@ -9,10 +9,17 @@ namespace WebApp.Pages public class IndexModel : PageModel { public List ProductsModel { get; set; } + public Dictionary> MediaByProductsModel { get; set; } public void OnGet() { - ProductsModel = APIClient.GetRequest>($"Product/GetFullList"); + ProductsModel = APIClient.GetRequest>($"Product/GetFullList"); + MediaByProductsModel = APIClient.GetRequest>>($"MediaFile/GetByProducts?"); + } + public List GetMediaByProduct(ProductViewModel productModel) + { + MediaByProductsModel.TryGetValue(productModel, out List models); + return models; } } }