Compare commits

..

No commits in common. "eeec81593be3a1179d0c325a193c070ad577d5a0" and "933a3bf3ea275e17fd77f69ed5891d4162feae86" have entirely different histories.

9 changed files with 101 additions and 169 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<PurchaseLogic> logger) public PurchaseLogic(IPurchaseStorage purchaseStorage, ILogger logger)
{ {
_purchaseStorage = purchaseStorage; _purchaseStorage = purchaseStorage;
_logger = logger; _logger = logger;

View File

@ -1,5 +1,4 @@
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;
@ -14,12 +13,12 @@ using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic namespace BusinessLogic.BusinessLogic
{ {
public class SellLogic : ISellLogic public class SellLogic
{ {
private readonly ISellStorage _sellStorage; private readonly ISellStorage _sellStorage;
private readonly ILogger _logger; private readonly ILogger _logger;
public SellLogic(ISellStorage sellStorage, ILogger<SellLogic> logger) public SellLogic(ISellStorage sellStorage, ILogger logger)
{ {
_sellStorage = sellStorage; _sellStorage = sellStorage;
_logger = logger; _logger = logger;
@ -34,7 +33,7 @@ namespace BusinessLogic.BusinessLogic
} }
return sell; return sell;
} }
public SellViewModel ReadElement(SellSearchModel model) public SellViewModel GetElement(SellSearchModel model)
{ {
ArgumentNullException.ThrowIfNull(model); ArgumentNullException.ThrowIfNull(model);
var sell = _sellStorage.GetElement(model); var sell = _sellStorage.GetElement(model);
@ -45,7 +44,7 @@ namespace BusinessLogic.BusinessLogic
return sell; return sell;
} }
public IEnumerable<SellViewModel> ReadElements(SellSearchModel? model) public IEnumerable<SellViewModel> GetElements(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)
@ -55,7 +54,6 @@ 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(SellSearchModel model); SellViewModel Update(SellBindingModel model);
SellViewModel ReadElement(SellSearchModel model); SellViewModel ReadElement(SellSearchModel model);

View File

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

View File

@ -1,83 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace RestAPI.Controllers
{
public class PurchaseController : Controller
{
// GET: PurchaseController
public ActionResult Index()
{
return View();
}
// GET: PurchaseController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: PurchaseController/Create
public ActionResult Create()
{
return View();
}
// POST: PurchaseController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: PurchaseController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: PurchaseController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: PurchaseController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: PurchaseController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}

View File

@ -20,17 +20,10 @@ 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,29 +1,30 @@
using Microsoft.AspNetCore.Http; using Contracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace RestAPI.Controllers namespace WebApp.Controllers
{ {
public class CartController : Controller public class HomeController : Controller
{ {
// GET: CartController // GET: HomeController
public ActionResult Index() public ActionResult Index()
{ {
return View(); return View(APIClient.GetRequest<List<ProductViewModel>>($"api/main/getfullproductslist"));
} }
// GET: CartController/Details/5 // GET: HomeController/Details/5
public ActionResult Details(int id) public ActionResult Details(int id)
{ {
return View(); return View();
} }
// GET: CartController/Create // GET: HomeController/Create
public ActionResult Create() public ActionResult Create()
{ {
return View(); return View();
} }
// POST: CartController/Create // POST: HomeController/Create
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection) public ActionResult Create(IFormCollection collection)
@ -38,13 +39,13 @@ namespace RestAPI.Controllers
} }
} }
// GET: CartController/Edit/5 // GET: HomeController/Edit/5
public ActionResult Edit(int id) public ActionResult Edit(int id)
{ {
return View(); return View();
} }
// POST: CartController/Edit/5 // POST: HomeController/Edit/5
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection) public ActionResult Edit(int id, IFormCollection collection)
@ -59,13 +60,13 @@ namespace RestAPI.Controllers
} }
} }
// GET: CartController/Delete/5 // GET: HomeController/Delete/5
public ActionResult Delete(int id) public ActionResult Delete(int id)
{ {
return View(); return View();
} }
// POST: CartController/Delete/5 // POST: HomeController/Delete/5
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection) public ActionResult Delete(int id, IFormCollection collection)

View File

@ -1,74 +1,81 @@
@page @using Contracts.ViewModels
@model WebApp.Pages.IndexModel
@model List<ProductViewModel>
@{ @{
ViewData["Title"] = "Catalog Page"; ViewData["Title"] = "Home 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>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <div class="collapse navbar-collapse">
<span class="navbar-toggler-icon"></span> <ul class="navbar-nav mr-auto">
</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-bs-toggle="dropdown" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Категории Категории
</a> </a>
@* МОЖНО РЕАЛИЗОВАТЬ ПОЗЖЕ *@ <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<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> <a class="dropdown-item" href="#">Винтовки</a>
<li><a class="dropdown-item" href="#">Винтовки</a></li> </div>
</ul>
</li> </li>
</ul> </ul>
<form class="d-flex" method="get"> <form method="get">
<input class="form-control me-2" type="search" placeholder="Поиск" name="search" value=""> <div class="form-inline col-lg-12">
<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 ms-3"> <div class="form-group">
<div class="d-flex align-items-center"> <form method="get" m>
<input type="range" step="1000" min="0" max="10000" value="50000" class="custom-range me-2" id="priceFrom"> <input type="range" step="100" min="0" max="10000" value="50000" class="custom-range" id="priceFrom">
<label for="priceFrom">От: <span id="priceLabelFrom">50 000</span> руб.</label> <label for="priceFrom">От: <span id="priceLabelFrom">50 000</span> руб.</label>
</div> </form>
<div class="d-flex align-items-center">
<input type="range" step="1000" min="0" max="100000" value="50000" class="custom-range me-2" id="priceTo"> <form method="get">
<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>
</div> </form>
</div>
</div> </div>
</div> </div>
</nav> </nav>
@* КАРТОЧКИ ТОВАРОВ *@ <!-- Таблица товаров -->
<div class="row row-cols-1 row-cols-md-3 g-6"> <table class="table">
@foreach (var weapon in @Model.ProductsModel) <thead>
<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)
{ {
<div class="card"> <tr>
<img src="#" class="card-img-top" alt="@weapon.Name"> <th scope="row">@Model.IndexOf(weapon)</th>
<div class="card-body"> <td>@weapon.Name</td>
<h5 class="card-title">@weapon.Name</h5> <td>@weapon.Price руб.</td>
<p class="card-text">Цена: >@weapon.Price руб.</p> <td><img src="@weapon" alt="@weapon.Name" style="width:100px;height:100px;"></td>
<a href="#" class="btn btn-primary">В корзину</a> </tr>
</div>
</div>
} }
</div> </tbody>
</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,18 +1,20 @@
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
{ {
public List<ProductViewModel> ProductsModel { get; set; } private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet() public void OnGet()
{ {
ProductsModel = APIClient.GetRequest<List<ProductViewModel>>($"Product/GetFullList");
} }
} }
} }