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 ILogger _logger;
public PurchaseLogic(IPurchaseStorage purchaseStorage, ILogger<PurchaseLogic> logger)
public PurchaseLogic(IPurchaseStorage purchaseStorage, ILogger logger)
{
_purchaseStorage = purchaseStorage;
_logger = logger;

View File

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

View File

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

View File

@ -11,18 +11,32 @@ namespace RestAPI.Controllers
{
[Route("[controller]/[action]")]
[ApiController]
public class ProductController
public class MainController
{
private readonly ILogger _logger;
private readonly IProductLogic _product;
public ProductController(ILogger<ProductController> logger, IProductLogic productLogic)
public MainController(ILogger<MainController> logger, IProductLogic productLogic)
{
_logger = logger;
_product = productLogic;
}
[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
{

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<IUserLogic, UserLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<ISellLogic, SellLogic>();
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
builder.Services.AddSingleton<ITwoFactorAuthService, TwoFactorAuthService>();
builder.Services.AddTransient<IRoleStorage, RoleStorage>();
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<MailSender>();

View File

@ -1,29 +1,30 @@
using Microsoft.AspNetCore.Http;
using Contracts.ViewModels;
using Microsoft.AspNetCore.Http;
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()
{
return View();
return View(APIClient.GetRequest<List<ProductViewModel>>($"api/main/getfullproductslist"));
}
// GET: CartController/Details/5
// GET: HomeController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: CartController/Create
// GET: HomeController/Create
public ActionResult Create()
{
return View();
}
// POST: CartController/Create
// POST: HomeController/Create
[HttpPost]
[ValidateAntiForgeryToken]
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)
{
return View();
}
// POST: CartController/Edit/5
// POST: HomeController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
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)
{
return View();
}
// POST: CartController/Delete/5
// POST: HomeController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)

View File

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

View File

@ -1,18 +1,20 @@
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; }
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
ProductsModel = APIClient.GetRequest<List<ProductViewModel>>($"Product/GetFullList");
}
}
}