Project create

This commit is contained in:
Илья Федотов 2024-05-28 18:22:47 +04:00
parent 25546c801e
commit 18c1eb5d5f
6 changed files with 19 additions and 30 deletions

View File

@ -12,7 +12,7 @@ namespace ElectronicsShopDataBaseImplement
optionsBuilder)
{
if (optionsBuilder.IsConfigured == false) {
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -3,6 +3,7 @@ using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
@ -21,7 +22,9 @@ namespace ElectronicsShopDataBaseImplement.Implements
using var context = new Database();
context.Products.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
return context.Products
.Include(x => x.CostItem)
.FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
}
public ProductViewModel? Update(ProductBindingModel model) {
@ -72,7 +75,9 @@ namespace ElectronicsShopDataBaseImplement.Implements
public List<ProductViewModel> GetFullList()
{
using var context = new Database();
return context.Products.Select(x => x.GetViewModel).ToList();
return context.Products
.Include(x => x.CostItem)
.Select(x => x.GetViewModel).ToList();
}
}
}

View File

@ -23,7 +23,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
if (APIEmployee.Employee == null) {
return Redirect("~/Home/Enter");
}
return View(APIEmployee.GetRequset<List<ProductViewModel>>($"api/main/getproducts?_employeeid={APIEmployee.Employee.ID}"));
return View(APIEmployee.GetRequset<List<ProductViewModel>>($"api/main/getproducts"));
}
[HttpGet]
@ -141,7 +141,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
}
[HttpPost]
public double Calc(int costitem, double productprice) {
public double Calc(int costitem, double productprice) {
var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={costitem}");
return productprice + (_costItem?.Price ?? 500);
}

View File

@ -15,7 +15,7 @@
<div class="row">
<div class="col-4">Статья затрат:</div>
<div class="col-8">
<select id="costitem" class="form-control" asp-items="@(new SelectList(ViewBag.CostItems, "ID", "Name"))"></select>
<select id="costitem" name="costitem" class="form-control" asp-items="@(new SelectList(ViewBag.CostItems, "ID", "Name"))"></select>
</div>
</div>
<div class="row">
@ -31,9 +31,9 @@
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8">
<input type="submit" value="Создать" class="btn btn-outline-primary" />
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Создать" class="btn btn-primary" />
</div>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
@ -43,8 +43,8 @@
$('#costitem').on('change', function () {
check();
});
$('#productprice'.on('change', function () {
check():
$('#productprice').on('change', function () {
check();
});
function check() {

View File

@ -18,7 +18,7 @@
return;
}
<p>
<a asp-action="CreateProduct">Создать Товар</a>
<a asp-action="CreateProduct">Создать товар</a>
</p>
<table class="table">
<thead>
@ -38,7 +38,7 @@
</th>
</thead>
<tbody>
@foreach (var item in Model) {
@foreach (var item in Model) {
<th>
<th>
@Html.DisplayFor(modelItem => item.ID)
@ -53,7 +53,7 @@
@Html.DisplayFor(modelItem => item.Price)
</th>
</th>
}
}
</tbody>
</table>
}

View File

@ -23,13 +23,6 @@ namespace ElectronicsShopRestAPI.Controllers {
_order = orderLogic;
}
[HttpGet]
public ProductViewModel? GetProduct(int ProductID) {
return null;
}
[HttpGet]
public List<ProductViewModel>? GetProducts() {
try {
@ -41,8 +34,6 @@ namespace ElectronicsShopRestAPI.Controllers {
}
}
// клиент должен получать свои заказы
// сотрудник должен получать все заказы
[HttpGet]
public List<OrderViewModel>? GetOrders(int _clientID) {
try
@ -72,12 +63,5 @@ namespace ElectronicsShopRestAPI.Controllers {
throw;
}
}
[HttpPost]
public void CreateProduct(OrderBindingModel model) {
return;
}
//Мейби нужны будут удаления, обновления, выбор конкретного заказа или продукта. Короче потом...
//А также для статей затрат.
}
}