продукты
This commit is contained in:
parent
b626bfda7d
commit
6aa55f1c11
@ -8,6 +8,6 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||
public IStoreKeeperModel StoreKeeper { get; set; }
|
||||
public int StoreKeeperId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,6 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||
public IStoreKeeperModel StoreKeeper { get; set; }
|
||||
public int StoreKeeperId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
{
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
public IStoreKeeperModel StoreKeeper { get; }
|
||||
public int StoreKeeperId { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
[NotMapped]
|
||||
IStoreKeeperModel IProductModel.StoreKeeper => StoreKeeper;
|
||||
public int StoreKeeperId { get; set; }
|
||||
public virtual StoreKeeper StoreKeeper {get; set;} = new();
|
||||
private Dictionary<int, (IComponentModel, int)>? _productComponents = null;
|
||||
[NotMapped]
|
||||
@ -65,7 +64,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
Name = Name,
|
||||
Price = Price,
|
||||
ProductComponents = ProductComponents,
|
||||
StoreKeeper = StoreKeeper,
|
||||
StoreKeeperId = StoreKeeperId,
|
||||
};
|
||||
|
||||
public static void UpdateComponents(ComputerHardwareStoreDBContext context, ProductBindingModel model)
|
||||
|
@ -18,46 +18,7 @@ namespace StoreKeeperClient.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
return View(APIClient.GetRequest<List<PurchaseViewModel>>($"api/main/getpurchases?storekeeperId={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.Client);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Privacy(string login, string password, string fio)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIClient.PostRequest("api/storekeeper/updatedata", new StoreKeeperBindingModel
|
||||
{
|
||||
Id = APIClient.Client.Id,
|
||||
Name = fio,
|
||||
Login = login,
|
||||
Password = password
|
||||
});
|
||||
APIClient.Client.Name = fio;
|
||||
APIClient.Client.Login = login;
|
||||
APIClient.Client.Password = password;
|
||||
Response.Redirect("Index");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -78,7 +39,7 @@ namespace StoreKeeperClient.Controllers
|
||||
{
|
||||
throw new Exception("Неверные почта и/или пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
Response.Redirect("Home/Index");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -104,6 +65,7 @@ namespace StoreKeeperClient.Controllers
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AddBuildToPurchase()
|
||||
{
|
||||
@ -195,13 +157,103 @@ namespace StoreKeeperClient.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ProductsList()
|
||||
public IActionResult Products()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
return View(new List<BuildViewModel>());
|
||||
return View(new List<ProductViewModel>());
|
||||
}
|
||||
|
||||
public IActionResult CreateProduct()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>($"api/component/getcomponents?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateProduct([FromBody] ProductBindingModel productModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(productModel.Name))
|
||||
{
|
||||
throw new Exception("Название не должно быть пустым");
|
||||
}
|
||||
if (productModel.Price <= 0)
|
||||
{
|
||||
throw new Exception("Цена должна быть больше 0");
|
||||
}
|
||||
productModel.StoreKeeperId = APIClient.Client.Id;
|
||||
APIClient.PostRequest("api/product/createproduct", productModel);
|
||||
}
|
||||
|
||||
public IActionResult UpdateProduct(int productid)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>($"api/component/getcomponents?userId={APIClient.Client.Id}");
|
||||
return View(productid);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateProduct([FromBody] ProductBindingModel productModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(productModel.Name))
|
||||
{
|
||||
throw new Exception("Название не должно быть пустым");
|
||||
}
|
||||
if (productModel.Price <= 0)
|
||||
{
|
||||
throw new Exception("Цена должна быть больше 0");
|
||||
}
|
||||
productModel.StoreKeeperId = APIClient.Client.Id;
|
||||
APIClient.PostRequest("api/product/updatedata", productModel);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteGood(int model)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
if (model <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификатор товара не может быть меньше или равен 0");
|
||||
}
|
||||
APIClient.PostRequest("api/product/deleteproduct", new ProductBindingModel
|
||||
{
|
||||
Id = model
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ProductViewModel? GetProduct(int Id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
if (Id <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификатор товара не может быть меньше или равен 0");
|
||||
}
|
||||
var result = APIClient.GetRequest<ProductViewModel>($"api/product/getproduct?id={Id}");
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -234,16 +286,6 @@ namespace StoreKeeperClient.Controllers
|
||||
return View(new List<PurchaseViewModel>());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult PurchaseUpdate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Report()
|
||||
{
|
||||
|
@ -20,6 +20,6 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
pattern: "{controller=Home}/{action=Enter}/{id?}");
|
||||
|
||||
app.Run();
|
||||
|
@ -34,3 +34,96 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
let list = [];
|
||||
const name = document.getElementById("name");
|
||||
const submitComponentBtn = document.getElementById("savecomponent");
|
||||
const saveBtn = document.getElementById("createproduct");
|
||||
const countElem = document.getElementById("count");
|
||||
const resultTable = document.getElementById("result");
|
||||
const totalPrice = document.getElementById("price");
|
||||
|
||||
submitComponentBtn.addEventListener("click", () => {
|
||||
console.log('try to add component')
|
||||
var count = $('#count').val();
|
||||
var component = $('#component').val();
|
||||
if (component && count && count > 0) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: `/Storekeeper/GetComponent`,
|
||||
data: { Id: component },
|
||||
success: function (result) {
|
||||
let flag = false
|
||||
if (list.length > 0) {
|
||||
list.forEach((elem) => {
|
||||
if (elem.component.id === parseInt(result.id)) {
|
||||
console.log('component already added')
|
||||
flag = true
|
||||
}
|
||||
})
|
||||
}
|
||||
if (!flag) list.push({ component: result, count: count })
|
||||
reloadTable()
|
||||
countElem.value = '1'
|
||||
}
|
||||
}).fail(function (xhr, textStatus, errorThrown) {
|
||||
alert(xhr.responseText);
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
saveBtn.addEventListener("click", () => {
|
||||
console.log('try to add product')
|
||||
if (list.length == 0) {
|
||||
alert('failed add product. components are empty')
|
||||
return
|
||||
}
|
||||
let components = []
|
||||
let counts = []
|
||||
list.forEach((x) => {
|
||||
components.push(x.component);
|
||||
counts.push(parseInt(x.count))
|
||||
})
|
||||
$.ajax(
|
||||
{
|
||||
url: `/Storekeeper/CreateProduct`,
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
"Name": name.value, "Price": parseFloat(totalPrice.value),
|
||||
"ProductComponentsComponents": components, "ProductComponentsCounts": counts
|
||||
})
|
||||
}
|
||||
).done(() => window.location.href = '/Storekeeper/Products')
|
||||
.fail(function (xhr, textStatus, errorThrown) {
|
||||
alert(xhr.responseText);
|
||||
})
|
||||
})
|
||||
|
||||
function reloadTable() {
|
||||
resultTable.innerHTML = ''
|
||||
let price = 0;
|
||||
let count = 0;
|
||||
list.forEach((elem) => {
|
||||
resultTable.innerHTML += `<tr><td>${elem.component.componentName}</td><td>${elem.component.cost}</td><td>${elem.count}</td><td>${Math.round(elem.component.cost * elem.count * 100) / 100}</td><td> \
|
||||
<div> \
|
||||
<button onclick="deleteComponent(${count})" type="button" class="btn btn-danger"> \
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> \
|
||||
</button> \
|
||||
</div><td/></tr>`
|
||||
count++;
|
||||
price += elem.component.cost * elem.count
|
||||
})
|
||||
totalPrice.value = Math.round(price * 100) / 100
|
||||
}
|
||||
|
||||
function deleteComponent(id) {
|
||||
list = list.filter(value => value.component.componentName != resultTable.rows[id].cells[0].innerText)
|
||||
reloadTable()
|
||||
}
|
||||
|
||||
</script>
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
@using ComputerHardwareStoreContracts.ViewModels
|
||||
@model List<OrderViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
@ -11,54 +10,8 @@
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
<h3 class="display-4">Добро пожаловать</h3>
|
||||
return;
|
||||
}
|
||||
<p>
|
||||
<a asp-action="Create">Создать заказ</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Изделие
|
||||
</th>
|
||||
<th>
|
||||
Дата создания
|
||||
</th>
|
||||
<th>
|
||||
Количество
|
||||
</th>
|
||||
<th>
|
||||
Сумма
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DateCreate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Sum)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Status)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
@ -28,6 +28,7 @@
|
||||
<th>
|
||||
Название
|
||||
</th>
|
||||
|
||||
<th>
|
||||
Цена
|
||||
</th>
|
||||
|
@ -20,9 +20,6 @@
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Components">Комплектующие</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using VendorClient.Models;
|
||||
@ -17,13 +18,46 @@ namespace VendorClient.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
if (APIClient.Vendor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
return View(APIClient.Vendor);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
if (APIClient.Vendor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.Vendor);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Privacy(string login, string password, string fio)
|
||||
{
|
||||
if (APIClient.Vendor == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIClient.PostRequest("api/vendor/updatedata", new VendorBindingModel
|
||||
{
|
||||
Id = APIClient.Vendor.Id,
|
||||
Name = fio,
|
||||
Login = login,
|
||||
Password = password
|
||||
});
|
||||
APIClient.Vendor.Name = fio;
|
||||
APIClient.Vendor.Login = login;
|
||||
APIClient.Vendor.Password = password;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -32,11 +66,44 @@ namespace VendorClient.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Enter(string login, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите почту и пароль");
|
||||
}
|
||||
APIClient.Vendor = APIClient.GetRequest<VendorViewModel>($"api/vendor/login?login={login}&password={password}");
|
||||
if (APIClient.Vendor == null)
|
||||
{
|
||||
throw new Exception("Неверные почта и/или пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
return;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void Register(string name, string login, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите логин, name, пароль");
|
||||
}
|
||||
APIClient.PostRequest("api/vendor/register", new VendorBindingModel
|
||||
{
|
||||
Name = name,
|
||||
Login = login,
|
||||
Password = password,
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AddBuildToPurchase()
|
||||
|
Loading…
Reference in New Issue
Block a user