NoWeb
This commit is contained in:
parent
03ddb8eb00
commit
9b14abf7e3
@ -12,7 +12,7 @@ namespace ElectronicsShopDataBaseImplement
|
||||
optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false) {
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(Database))]
|
||||
[Migration("20240528050446_Init")]
|
||||
[Migration("20240529092847_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -73,6 +73,8 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("EmployeeID");
|
||||
|
||||
b.ToTable("CostItems");
|
||||
});
|
||||
|
||||
@ -204,9 +206,22 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("CostItemID");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Employee", "Employee")
|
||||
.WithMany()
|
||||
.HasForeignKey("EmployeeID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null)
|
||||
@ -240,6 +255,17 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
.HasForeignKey("PaymentID");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem")
|
||||
.WithMany()
|
||||
.HasForeignKey("CostItemID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CostItem");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
@ -26,22 +26,6 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
table.PrimaryKey("PK_Clients", x => x.ID);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CostItems",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
EmployeeID = table.Column<int>(type: "int", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false),
|
||||
CostNum = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CostItems", x => x.ID);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Employees",
|
||||
columns: table => new
|
||||
@ -57,21 +41,6 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
table.PrimaryKey("PK_Employees", x => x.ID);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Products",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ProductName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false),
|
||||
CostItemID = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Products", x => x.ID);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
@ -93,6 +62,71 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CostItems",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
EmployeeID = table.Column<int>(type: "int", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false),
|
||||
CostNum = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CostItems", x => x.ID);
|
||||
table.ForeignKey(
|
||||
name: "FK_CostItems_Employees_EmployeeID",
|
||||
column: x => x.EmployeeID,
|
||||
principalTable: "Employees",
|
||||
principalColumn: "ID",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Paymeants",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ProductID = table.Column<int>(type: "int", nullable: false),
|
||||
OrderID = table.Column<int>(type: "int", nullable: false),
|
||||
SumPayment = table.Column<double>(type: "float", nullable: false),
|
||||
PayOption = table.Column<int>(type: "int", nullable: false),
|
||||
PaymentID = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Paymeants", x => x.ID);
|
||||
table.ForeignKey(
|
||||
name: "FK_Paymeants_Orders_PaymentID",
|
||||
column: x => x.PaymentID,
|
||||
principalTable: "Orders",
|
||||
principalColumn: "ID");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Products",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ProductName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false),
|
||||
CostItemID = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Products", x => x.ID);
|
||||
table.ForeignKey(
|
||||
name: "FK_Products_CostItems_CostItemID",
|
||||
column: x => x.CostItemID,
|
||||
principalTable: "CostItems",
|
||||
principalColumn: "ID",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "OrderProducts",
|
||||
columns: table => new
|
||||
@ -120,27 +154,10 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
principalColumn: "ID");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Paymeants",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ProductID = table.Column<int>(type: "int", nullable: false),
|
||||
OrderID = table.Column<int>(type: "int", nullable: false),
|
||||
SumPayment = table.Column<double>(type: "float", nullable: false),
|
||||
PayOption = table.Column<int>(type: "int", nullable: false),
|
||||
PaymentID = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Paymeants", x => x.ID);
|
||||
table.ForeignKey(
|
||||
name: "FK_Paymeants_Orders_PaymentID",
|
||||
column: x => x.PaymentID,
|
||||
principalTable: "Orders",
|
||||
principalColumn: "ID");
|
||||
});
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CostItems_EmployeeID",
|
||||
table: "CostItems",
|
||||
column: "EmployeeID");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderProducts__productID",
|
||||
@ -161,17 +178,16 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
name: "IX_Paymeants_PaymentID",
|
||||
table: "Paymeants",
|
||||
column: "PaymentID");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Products_CostItemID",
|
||||
table: "Products",
|
||||
column: "CostItemID");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "CostItems");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Employees");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "OrderProducts");
|
||||
|
||||
@ -184,8 +200,14 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "CostItems");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Employees");
|
||||
}
|
||||
}
|
||||
}
|
@ -70,6 +70,8 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("EmployeeID");
|
||||
|
||||
b.ToTable("CostItems");
|
||||
});
|
||||
|
||||
@ -201,9 +203,22 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("CostItemID");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Employee", "Employee")
|
||||
.WithMany()
|
||||
.HasForeignKey("EmployeeID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null)
|
||||
@ -237,6 +252,17 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
.HasForeignKey("PaymentID");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem")
|
||||
.WithMany()
|
||||
.HasForeignKey("CostItemID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CostItem");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
|
@ -33,7 +33,22 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ProductViewModel? GetPoduct(int productID)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _product.ReadElement(new ProductSearchModel
|
||||
{
|
||||
ID = productID
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения суши по id={Id}", productID);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<OrderViewModel>? GetOrders(int _clientID) {
|
||||
try
|
||||
|
@ -1,5 +1,6 @@
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using ElectronicsShopDataModels.Models;
|
||||
using ElectronicsShopUserApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
@ -75,7 +76,7 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
public IActionResult Register() {
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(string email, string password, string fio) {
|
||||
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) {
|
||||
throw new Exception("Ââåäèòå ïî÷òó,ïàðîëü è ÔÈÎ");
|
||||
@ -91,17 +92,37 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Create() {
|
||||
ViewBag.Orders = APIClient.GetRequset<List<OrderViewModel>>("api/main/getproductlist");
|
||||
ViewBag.Products = APIClient.GetRequset<List<ProductViewModel>>("api/main/getproducts");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(OrderBindingModel order) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
|
||||
private double Calc() {
|
||||
throw new NotImplementedException();
|
||||
if (order.ProductList.Count <= 0)
|
||||
{
|
||||
throw new Exception("Êîëè÷åñòâî è ñóììà äîëæíû áûòü áîëüøå 0");
|
||||
}
|
||||
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
|
||||
{
|
||||
ClientID = APIClient.Client.ID,
|
||||
Sum = Calc(order.ProductList),
|
||||
ProductList = order.ProductList,
|
||||
DateCreate = DateTime.Now,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpPost]
|
||||
private double Calc(Dictionary<int, (IProductModel, int)> ProductList)
|
||||
{
|
||||
Double Sum = 0;
|
||||
foreach (var ProductItem in ProductList)
|
||||
{
|
||||
Sum += (ProductItem.Value.Item1.Price * ProductItem.Value.Item2);
|
||||
}
|
||||
return Sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,60 @@
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание заказа</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Product:</div>
|
||||
<div class="col-8">
|
||||
<select id="product" name="product" class="form-control">
|
||||
@foreach (var product in ViewBag.Products)
|
||||
{
|
||||
<option value="@product.ID">@product.ProductName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="count" id="count" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Сумма:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" id="sum" name="sum" readonly />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Создать" class="btn btn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
$('#product').on('change', function () {
|
||||
check();
|
||||
});
|
||||
$('#count').on('change', function () {
|
||||
check();
|
||||
});
|
||||
function check() {
|
||||
var count = $('#count').val();
|
||||
var product = $('#product').val();
|
||||
if (count && product) {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "/Home/Calc",
|
||||
data: { count: count, product: product },
|
||||
success: function (result) {
|
||||
var roundedResult = parseFloat(result).toFixed(2);
|
||||
$("#sum").val(roundedResult);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user