Да уж духотища но я начал хотя бы контроллеры и вьюшки
This commit is contained in:
parent
d2d51532a4
commit
7938a755b7
@ -80,5 +80,23 @@ namespace DatabaseImplement.Models
|
||||
DateSell = model.DateSell;
|
||||
UserId = model.UserId;
|
||||
}
|
||||
public void UpdateProducts(Database context, SellBindingModel model)
|
||||
{
|
||||
var sellProducts = context.SellProducts.Where(rec =>
|
||||
rec.Id == model.Id).ToList();
|
||||
if (sellProducts != null && sellProducts.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.SellProducts.RemoveRange(sellProducts.Where(rec
|
||||
=> !model.SellProducts.ContainsKey(rec.ProductId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateProduct in sellProducts)
|
||||
{
|
||||
updateProduct.Count = model.SellProducts[updateProduct.ProductId].Item2;
|
||||
model.SellProducts.Remove(updateProduct.ProductId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
78
RestAPI/Controllers/MainController.cs
Normal file
78
RestAPI/Controllers/MainController.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using BusinessLogic.BusinessLogic;
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicContracts;
|
||||
using Contracts.Exceptions;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace RestAPI.Controllers
|
||||
{
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class MainController
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductLogic _product;
|
||||
|
||||
public MainController(ILogger<MainController> logger, IProductLogic productLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_product = productLogic;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<ProductViewModel>? GetProductList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _product.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка пакетов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
public IResult Update([FromBody] ProductBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = _product.Update(model);
|
||||
return Results.Ok(res);
|
||||
}
|
||||
catch (AccountException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Wrong update data");
|
||||
return Results.BadRequest(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error update user");
|
||||
return Results.Problem(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public IResult Delete(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = _product.Delete(new() { Id = id });
|
||||
return Results.Ok(res);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogInformation(ex, "User not found");
|
||||
return Results.NoContent();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error delete user");
|
||||
return Results.Problem(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,56 @@
|
||||
@page
|
||||
@model WebApp.Pages.CatalogModel
|
||||
@{
|
||||
ViewData["Title"] = "Каталог оружия";
|
||||
}
|
||||
<!-- Шапка -->
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a class="navbar-brand" href="#">Catalog</a>
|
||||
<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-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Категории
|
||||
</a>
|
||||
<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 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">
|
||||
<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>
|
||||
</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>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
document.getElementById("priceFrom").addEventListener("input", function () {
|
||||
var price = this.value;
|
||||
document.getElementById("priceLabelFrom").textContent = price + " руб.";
|
||||
// Здесь должен быть код для фильтрации товаров по цене
|
||||
});
|
||||
|
||||
document.getElementById("priceTo").addEventListener("input", function () {
|
||||
var price = this.value;
|
||||
document.getElementById("priceLabelTo").textContent = price + " руб.";
|
||||
// Здесь должен быть код для фильтрации товаров по цене
|
||||
});
|
||||
</script>
|
||||
}
|
@ -7,6 +7,10 @@
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/WebApp.styles.css" asp-append-version="true" />
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
@ -23,10 +27,16 @@
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Catalog">Catalog</a>
|
||||
</li>
|
||||
@* <li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</li> *@
|
||||
@if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Cart">Cart</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/User/Index">Profile</a>
|
||||
</li>
|
||||
|
Loading…
Reference in New Issue
Block a user