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) optionsBuilder)
{ {
if (optionsBuilder.IsConfigured == false) { 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); base.OnConfiguring(optionsBuilder);
} }

View File

@ -3,6 +3,7 @@ using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts; using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels; using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models; using ElectronicsShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -21,7 +22,9 @@ namespace ElectronicsShopDataBaseImplement.Implements
using var context = new Database(); using var context = new Database();
context.Products.Add(newComponent); context.Products.Add(newComponent);
context.SaveChanges(); context.SaveChanges();
return newComponent.GetViewModel; return context.Products
.Include(x => x.CostItem)
.FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
} }
public ProductViewModel? Update(ProductBindingModel model) { public ProductViewModel? Update(ProductBindingModel model) {
@ -72,7 +75,9 @@ namespace ElectronicsShopDataBaseImplement.Implements
public List<ProductViewModel> GetFullList() public List<ProductViewModel> GetFullList()
{ {
using var context = new Database(); 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) { if (APIEmployee.Employee == null) {
return Redirect("~/Home/Enter"); 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] [HttpGet]
@ -141,7 +141,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
} }
[HttpPost] [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}"); var _costItem = APIEmployee.GetRequset<CostItemViewModel>($"api/employee/getcostitem?_costitemid={costitem}");
return productprice + (_costItem?.Price ?? 500); return productprice + (_costItem?.Price ?? 500);
} }

View File

@ -15,7 +15,7 @@
<div class="row"> <div class="row">
<div class="col-4">Статья затрат:</div> <div class="col-4">Статья затрат:</div>
<div class="col-8"> <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> </div>
<div class="row"> <div class="row">
@ -31,9 +31,9 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4"></div> <div class="col-8"></div>
<div class="col-8"> <div class="col-4">
<input type="submit" value="Создать" class="btn btn-outline-primary" /> <input type="submit" value="Создать" class="btn btn-primary" />
</div> </div>
</div> </div>
<script src="~/lib/jquery/dist/jquery.min.js"></script> <script src="~/lib/jquery/dist/jquery.min.js"></script>
@ -43,8 +43,8 @@
$('#costitem').on('change', function () { $('#costitem').on('change', function () {
check(); check();
}); });
$('#productprice'.on('change', function () { $('#productprice').on('change', function () {
check(): check();
}); });
function check() { function check() {

View File

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

View File

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