This commit is contained in:
devil_1nc 2024-06-25 15:03:16 +04:00
parent e1673bca2c
commit eeec81593b
8 changed files with 74 additions and 173 deletions

View File

@ -23,7 +23,7 @@ namespace BusinessLogic.BusinessLogic
private readonly IPurchaseStorage _purchaseStorage; private readonly IPurchaseStorage _purchaseStorage;
private readonly ILogger _logger; private readonly ILogger _logger;
public PurchaseLogic(IPurchaseStorage purchaseStorage, ILogger logger) public PurchaseLogic(IPurchaseStorage purchaseStorage, ILogger<PurchaseLogic> logger)
{ {
_purchaseStorage = purchaseStorage; _purchaseStorage = purchaseStorage;
_logger = logger; _logger = logger;

View File

@ -1,4 +1,5 @@
using Contracts.BindingModels; using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.Converters; using Contracts.Converters;
using Contracts.SearchModels; using Contracts.SearchModels;
using Contracts.StorageContracts; using Contracts.StorageContracts;
@ -13,12 +14,12 @@ using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic namespace BusinessLogic.BusinessLogic
{ {
public class SellLogic public class SellLogic : ISellLogic
{ {
private readonly ISellStorage _sellStorage; private readonly ISellStorage _sellStorage;
private readonly ILogger _logger; private readonly ILogger _logger;
public SellLogic(ISellStorage sellStorage, ILogger logger) public SellLogic(ISellStorage sellStorage, ILogger<SellLogic> logger)
{ {
_sellStorage = sellStorage; _sellStorage = sellStorage;
_logger = logger; _logger = logger;
@ -33,7 +34,7 @@ namespace BusinessLogic.BusinessLogic
} }
return sell; return sell;
} }
public SellViewModel GetElement(SellSearchModel model) public SellViewModel ReadElement(SellSearchModel model)
{ {
ArgumentNullException.ThrowIfNull(model); ArgumentNullException.ThrowIfNull(model);
var sell = _sellStorage.GetElement(model); var sell = _sellStorage.GetElement(model);
@ -44,7 +45,7 @@ namespace BusinessLogic.BusinessLogic
return sell; return sell;
} }
public IEnumerable<SellViewModel> GetElements(SellSearchModel? model) public IEnumerable<SellViewModel> ReadElements(SellSearchModel? model)
{ {
var sell_list = _sellStorage.GetFullList(model); var sell_list = _sellStorage.GetFullList(model);
if (sell_list is null || sell_list.Count() == 0) if (sell_list is null || sell_list.Count() == 0)
@ -54,6 +55,7 @@ namespace BusinessLogic.BusinessLogic
} }
return sell_list; return sell_list;
} }
public SellViewModel Update(SellSearchModel model) public SellViewModel Update(SellSearchModel model)
{ {
ArgumentNullException.ThrowIfNull(model); ArgumentNullException.ThrowIfNull(model);

View File

@ -13,7 +13,7 @@ namespace Contracts.BusinessLogicContracts
{ {
SellViewModel Create(SellBindingModel model); SellViewModel Create(SellBindingModel model);
SellViewModel Update(SellBindingModel model); SellViewModel Update(SellSearchModel model);
SellViewModel ReadElement(SellSearchModel model); SellViewModel ReadElement(SellSearchModel model);

View File

@ -11,32 +11,18 @@ namespace RestAPI.Controllers
{ {
[Route("[controller]/[action]")] [Route("[controller]/[action]")]
[ApiController] [ApiController]
public class MainController public class ProductController
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IProductLogic _product; private readonly IProductLogic _product;
public MainController(ILogger<MainController> logger, IProductLogic productLogic) public ProductController(ILogger<ProductController> logger, IProductLogic productLogic)
{ {
_logger = logger; _logger = logger;
_product = productLogic; _product = productLogic;
} }
[HttpGet] [HttpGet]
public List<ProductViewModel>? GetFullProductList() public List<ProductViewModel>? GetFullList()
{
try
{
return _product.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов");
throw;
}
}
[HttpGet]
public List<ProductViewModel>? GetFilteredProductList()
{ {
try try
{ {

View File

@ -20,10 +20,17 @@ builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IRoleLogic, RoleLogic>(); builder.Services.AddTransient<IRoleLogic, RoleLogic>();
builder.Services.AddTransient<IUserLogic, UserLogic>(); builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<ISellLogic, SellLogic>();
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
builder.Services.AddSingleton<ITwoFactorAuthService, TwoFactorAuthService>(); builder.Services.AddSingleton<ITwoFactorAuthService, TwoFactorAuthService>();
builder.Services.AddTransient<IRoleStorage, RoleStorage>(); builder.Services.AddTransient<IRoleStorage, RoleStorage>();
builder.Services.AddTransient<IUserStorage, UserStorage>(); builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<ISellStorage, SellStorage>();
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
builder.Services.AddSingleton<JwtProvider>(); builder.Services.AddSingleton<JwtProvider>();
builder.Services.AddSingleton<MailSender>(); builder.Services.AddSingleton<MailSender>();

View File

@ -1,85 +0,0 @@
using Contracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace WebApp.Controllers
{
public class HomeController : Controller
{
// GET: HomeController
public ActionResult Index()
{
return Redirect("~/Home/Enter");
return View(APIClient.GetRequest<List<ProductViewModel>>($"api/main/getfullproductslist"));
}
// GET: HomeController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: HomeController/Create
public ActionResult Create()
{
return View();
}
// POST: HomeController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: HomeController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: HomeController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: HomeController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: HomeController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}

View File

@ -1,81 +1,74 @@
@using Contracts.ViewModels @page
@model WebApp.Pages.IndexModel
@model List<ProductViewModel>
@{ @{
ViewData["Title"] = "Home page"; ViewData["Title"] = "Catalog Page";
} }
<!-- Шапка --> <!-- Шапка -->
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">Catalog</a> <a class="navbar-brand" href="#">Catalog</a>
<div class="collapse navbar-collapse"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<ul class="navbar-nav mr-auto"> <span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Категории Категории
</a> </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> @* МОЖНО РЕАЛИЗОВАТЬ ПОЗЖЕ *@
<a class="dropdown-item" href="#">Пистолеты</a> <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Револьверы</a> <li><a class="dropdown-item" href="#">Пистолеты</a></li>
<a class="dropdown-item" href="#">Винтовки</a> <li><a class="dropdown-item" href="#">Револьверы</a></li>
</div> <li><a class="dropdown-item" href="#">Винтовки</a></li>
</ul>
</li> </li>
</ul> </ul>
<form method="get"> <form class="d-flex" method="get">
<div class="form-inline col-lg-12"> <input class="form-control me-2" type="search" placeholder="Поиск" name="search" value="">
<input class="form-control mr-sm-2" type="search" placeholder="Поиск" name="search" value="">
<button class="btn btn-outline-success" type="submit"><i class="fas fa-search"></i></button> <button class="btn btn-outline-success" type="submit"><i class="fas fa-search"></i></button>
</div>
</form> </form>
<div class="form-group"> <div class="form-group ms-3">
<form method="get" m> <div class="d-flex align-items-center">
<input type="range" step="100" min="0" max="10000" value="50000" class="custom-range" id="priceFrom"> <input type="range" step="1000" min="0" max="10000" value="50000" class="custom-range me-2" id="priceFrom">
<label for="priceFrom">От: <span id="priceLabelFrom">50 000</span> руб.</label> <label for="priceFrom">От: <span id="priceLabelFrom">50 000</span> руб.</label>
</form> </div>
<div class="d-flex align-items-center">
<form method="get"> <input type="range" step="1000" min="0" max="100000" value="50000" class="custom-range me-2" id="priceTo">
<input type="range" step="100" min="0" max="100000" value="50000" class="custom-range" id="priceTo">
<label for="priceTo">До: <span id="priceLabelTo">50 000</span> руб.</label> <label for="priceTo">До: <span id="priceLabelTo">50 000</span> руб.</label>
</form> </div>
</div>
</div> </div>
</div> </div>
</nav> </nav>
<!-- Таблица товаров --> @* КАРТОЧКИ ТОВАРОВ *@
<table class="table"> <div class="row row-cols-1 row-cols-md-3 g-6">
<thead> @foreach (var weapon in @Model.ProductsModel)
<tr>
<th scope="col">#</th>
<th scope="col">Название</th>
<th scope="col">Цена</th>
<th scope="col">Изображение</th>
</tr>
</thead>
<tbody>
@foreach (var weapon in Model)
{ {
<tr> <div class="card">
<th scope="row">@Model.IndexOf(weapon)</th> <img src="#" class="card-img-top" alt="@weapon.Name">
<td>@weapon.Name</td> <div class="card-body">
<td>@weapon.Price руб.</td> <h5 class="card-title">@weapon.Name</h5>
<td><img src="@weapon" alt="@weapon.Name" style="width:100px;height:100px;"></td> <p class="card-text">Цена: >@weapon.Price руб.</p>
</tr> <a href="#" class="btn btn-primary">В корзину</a>
</div>
</div>
} }
</tbody> </div>
</table>
@section Scripts { @section Scripts {
<script> <script>
// СЛАЙДЕРЫ
document.getElementById("priceFrom").addEventListener("input", function () { document.getElementById("priceFrom").addEventListener("input", function () {
var price = this.value; var price = this.value;
document.getElementById("priceLabelFrom").textContent = price + " руб."; document.getElementById("priceLabelFrom").textContent = price + " р.";
// Здесь должен быть код для фильтрации товаров по цене
}); });
document.getElementById("priceTo").addEventListener("input", function () { document.getElementById("priceTo").addEventListener("input", function () {
var price = this.value; var price = this.value;
document.getElementById("priceLabelTo").textContent = price + " руб."; document.getElementById("priceLabelTo").textContent = price + " р.";
// Здесь должен быть код для фильтрации товаров по цене
}); });
</script> </script>
} }

View File

@ -1,20 +1,18 @@
using Contracts.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages namespace WebApp.Pages
{ {
[AllowAnonymous]
public class IndexModel : PageModel public class IndexModel : PageModel
{ {
private readonly ILogger<IndexModel> _logger; public List<ProductViewModel> ProductsModel { get; set; }
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet() public void OnGet()
{ {
ProductsModel = APIClient.GetRequest<List<ProductViewModel>>($"Product/GetFullList");
} }
} }
} }