Complete lab 5 hard

This commit is contained in:
Viltskaa 2023-04-25 10:31:41 +04:00
parent 1b441456c4
commit 26ed5c0d05
20 changed files with 819 additions and 37 deletions

View File

@ -17,11 +17,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarFileImplement", "Su
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarRestApi", "SushiBarRestApi\SushiBarRestApi.csproj", "{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarRestApi", "SushiBarRestApi\SushiBarRestApi.csproj", "{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarClientApi", "SushiBarClientApi\SushiBarClientApi.csproj", "{BF58D50B-0408-4124-8CD3-1D5DFEE83104}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarClientApi", "SushiBarClientApi\SushiBarClientApi.csproj", "{BF58D50B-0408-4124-8CD3-1D5DFEE83104}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarStoresMvc", "SushiBarStoresMvc\SushiBarStoresMvc.csproj", "{7D14BA90-5923-45CE-9245-EB6686B5B8F6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarStoresMvc", "SushiBarStoresMvc\SushiBarStoresMvc.csproj", "{7D14BA90-5923-45CE-9245-EB6686B5B8F6}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -109,7 +109,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
} }
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", store.Id, store.StoreName); _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", store.Id, store.StoreName);
int countSushi = store.Sushis.Sum(s => s.Value.Item2); var countSushi = store.Sushis.Sum(s => s.Value.Item2);
if (store.maxSushi - countSushi >= quantity) if (store.maxSushi - countSushi >= quantity)
{ {
if (store.Sushis.TryGetValue(sushi.Id, out var pair)) if (store.Sushis.TryGetValue(sushi.Id, out var pair))

View File

@ -0,0 +1,290 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SushiBarDatabaseImplement;
#nullable disable
namespace SushiBarDatabaseImplement.Migrations
{
[DbContext(typeof(SushiBarDatabase))]
[Migration("20230425050030_lab5hard")]
partial class lab5hard
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.Property<int>("SushiId")
.HasColumnType("int");
b.Property<string>("SushiName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("SushiId");
b.ToTable("Orders");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Store", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");
b.Property<string>("StoreAddress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("StoreName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("maxSushi")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Stores");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.StoreSushi", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("StoreId")
.HasColumnType("int");
b.Property<int>("SushiId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StoreId");
b.HasIndex("SushiId");
b.ToTable("StoreSushis");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("SushiName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("SushiId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("SushiId");
b.ToTable("SushiComponents");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
.WithMany("Orders")
.HasForeignKey("SushiId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.StoreSushi", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Store", "Store")
.WithMany("StoreSushi")
.HasForeignKey("StoreId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
.WithMany()
.HasForeignKey("SushiId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Store");
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component")
.WithMany("SushiComponent")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
.WithMany("Components")
.HasForeignKey("SushiId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b =>
{
b.Navigation("SushiComponent");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Store", b =>
{
b.Navigation("StoreSushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,215 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SushiBarDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class lab5hard : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientFio = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Stores",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
StoreName = table.Column<string>(type: "nvarchar(max)", nullable: false),
StoreAddress = table.Column<string>(type: "nvarchar(max)", nullable: false),
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
maxSushi = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stores", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sushi",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SushiName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Sushi", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SushiId = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false),
SushiName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Sushi_SushiId",
column: x => x.SushiId,
principalTable: "Sushi",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "StoreSushis",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SushiId = table.Column<int>(type: "int", nullable: false),
StoreId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StoreSushis", x => x.Id);
table.ForeignKey(
name: "FK_StoreSushis_Stores_StoreId",
column: x => x.StoreId,
principalTable: "Stores",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StoreSushis_Sushi_SushiId",
column: x => x.SushiId,
principalTable: "Sushi",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SushiComponents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SushiId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SushiComponents", x => x.Id);
table.ForeignKey(
name: "FK_SushiComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SushiComponents_Sushi_SushiId",
column: x => x.SushiId,
principalTable: "Sushi",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_SushiId",
table: "Orders",
column: "SushiId");
migrationBuilder.CreateIndex(
name: "IX_StoreSushis_StoreId",
table: "StoreSushis",
column: "StoreId");
migrationBuilder.CreateIndex(
name: "IX_StoreSushis_SushiId",
table: "StoreSushis",
column: "SushiId");
migrationBuilder.CreateIndex(
name: "IX_SushiComponents_ComponentId",
table: "SushiComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_SushiComponents_SushiId",
table: "SushiComponents",
column: "SushiId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "StoreSushis");
migrationBuilder.DropTable(
name: "SushiComponents");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Stores");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Sushi");
}
}
}

View File

@ -0,0 +1,46 @@
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json;
namespace SushiBarStoreApi;
public static class ApiStores
{
private static readonly HttpClient _client = new();
private static string _password = string.Empty;
public static bool Access { get; private set; }
public static void Connect(IConfiguration configuration)
{
_password = configuration["PasswordStore"];
_client.BaseAddress = new Uri(configuration["IPAddress"]);
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public static T? GetRequest<T>(string requestUrl)
{
var response = _client.GetAsync(requestUrl);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<T>(result);
}
throw new Exception(result);
}
public static void PostRequest<T>(string requestUrl, T model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8,"application/json");
var response = _client.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(result);
}
}
public static void GetAccess(string password)
{
Access = _password == password;
}
}

View File

@ -0,0 +1 @@
<h1>ABOBA</h1>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "Enter";
}
<div class="text-center">
<h2 class="display-4">Sign in</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Password:</div>
<div class="col-8"><input type="password" name="password" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Enter" class="btn btn-primary"/>
</div>
</div>
</form>

View File

@ -0,0 +1,8 @@
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

View File

@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

View File

@ -9,20 +9,13 @@ namespace SushiBarStoresMvc.Controllers;
public class HomeController : Controller public class HomeController : Controller
{ {
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index() public IActionResult Index()
{ {
if (!ApiStores.Access) if (!ApiStores.Access)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(ApiStores.GetRequest<List<StoreViewModel>>($"api/Store/GetStores")); return View(ApiStores.GetRequest<List<StoreViewModel>>("api/Store/GetStores"));
} }
[HttpGet] [HttpGet]
@ -109,7 +102,7 @@ public class HomeController : Controller
[HttpGet] [HttpGet]
public IActionResult Update() public IActionResult Update()
{ {
if (ApiStores.Access == false) if (!ApiStores.Access)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
@ -120,7 +113,7 @@ public class HomeController : Controller
[HttpPost] [HttpPost]
public void Update(int store, string name, string address, DateTime date, int count) public void Update(int store, string name, string address, DateTime date, int count)
{ {
if (ApiStores.Access == false) if (!ApiStores.Access)
{ {
throw new Exception("Need auth"); throw new Exception("Need auth");
} }
@ -150,7 +143,7 @@ public class HomeController : Controller
[HttpGet] [HttpGet]
public Tuple<StoreViewModel, string>? GetStore(int storeId) public Tuple<StoreViewModel, string>? GetStore(int storeId)
{ {
if (ApiStores.Access == false) if (!ApiStores.Access)
{ {
throw new Exception("Need auth"); throw new Exception("Need auth");
} }
@ -169,25 +162,25 @@ public class HomeController : Controller
public IActionResult Supply() public IActionResult Supply()
{ {
if (ApiStores.Access == false) if (!ApiStores.Access)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.Stores = ApiStores.GetRequest<List<StoreViewModel>>("api/store/GetStores"); ViewBag.Stores = ApiStores.GetRequest<List<StoreViewModel>>("api/Store/GetStores");
ViewBag.Packages = ApiStores.GetRequest<List<SushiViewModel>>("api/main/GetSushiList"); ViewBag.Sushi = ApiStores.GetRequest<List<SushiViewModel>>("api/Main/GetProductList");
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Supply(int store, int package, int count) public void Supply(int store, int sushi, int count)
{ {
if (ApiStores.Access == false) if (!ApiStores.Access)
{ {
throw new Exception("Need auth"); throw new Exception("Need auth");
} }
ApiStores.PostRequest("api/store/Supply", Tuple.Create( ApiStores.PostRequest("api/store/Supply", Tuple.Create(
new StoreSearchModel { Id = store }, new StoreSearchModel { Id = store },
new SushiViewModel { Id = package }, new SushiViewModel { Id = sushi },
count count
)); ));
Response.Redirect("Index"); Response.Redirect("Index");

View File

@ -1 +1,31 @@
<h1>ABOBA</h1> @{
ViewData["Title"] = "Create";
}
<div class="text-center">
<h2 class="display-4">Create</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Name:</div>
<div class="col-8"><input type="text" name="name" id="name" class="form-control"/></div>
</div>
<div class="row">
<div class="col-4">Address:</div>
<div class="col-8"><input type="text" id="address" name="address" class="form-control"/></div>
</div>
<div class="row">
<div class="col-4">Max sushi:</div>
<div class="col-8"><input type="number" id="count" name="count" class="form-control"/></div>
</div>
<div class="row">
<div class="col-4">Date opening:</div>
<div class="col-8"><input type="date" id="date" name="date" class="form-control" required/></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Create" class="btn btn-primary"/>
</div>
</div>
</form>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "Delete";
}
<div class="text-center">
<h2 class="display-4">Delete store</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Store:</div>
<div class="col-8">
<select id="store" name="store" class="form-control" asp-items="@(new SelectList(@ViewBag.Stores, "Id", "StoreName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Delete" class="btn btn-danger" /></div>
</div>
</form>

View File

@ -1,8 +1,60 @@
@{ @using Microsoft.AspNetCore.Mvc.TagHelpers
@model List<SushiBarContracts.ViewModels.StoreViewModel>
@{
ViewData["Title"] = "Home Page"; ViewData["Title"] = "Home Page";
} }
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Welcome</h1> <h1 class="display-4">Stores</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> </div>
<div class="text-center">
@{
<p>
<a asp-action="Create">Create</a>
<a asp-action="Update">Edit</a>
<a asp-action="Delete">Delete</a>
<a asp-action="Supply">Supply</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Name
</th>
<th>
Address
</th>
<th>
Date opening
</th>
<th>
Max sushi
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.StoreName)
</td>
<td>
@Html.DisplayFor(modelItem => item.StoreAddress)
</td>
<td>
@Html.DisplayFor(modelItem => item.OpeningDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.maxSushi)
</td>
</tr>
}
</tbody>
</table>
}
</div> </div>

View File

@ -0,0 +1,37 @@
@{
ViewData["Title"] = "Create";
}
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Dictionary<int, (SushiBarDataModels.Models.ISushiModel, int)>
<div class="text-center">
<h2 class="display-4">Add sushi to store</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Store:</div>
<div class="col-8">
<select id="store" name="store" class="form-control" asp-items="@(new SelectList(ViewBag.Stores, "Id", "StoreName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Sushi:</div>
<div class="col-8">
<select id="sushi" name="sushi" class="form-control" asp-items="@(new SelectList(ViewBag.Sushi, "Id", "SushiName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Count:</div>
<div class="col-8">
<input type="number" id="count" name="count" min="1" class="form-control"/>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Supply" class="btn btn-primary"/>
</div>
</div>
</form>

View File

@ -0,0 +1,79 @@
@{
ViewData["Title"] = "Update";
}
<div class="text-center">
<h2 class="display-4">Edit store</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Store:</div>
<div class="col-8">
<select id="store" name="store" class="form-control" asp-items="@(new SelectList(ViewBag.Stores, "Id", "StoreName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Name:</div>
<div class="col-8"><input type="text" name="name" id="name" class="form-control"/></div>
</div>
<div class="row">
<div class="col-4">Address:</div>
<div class="col-8"><input type="text" id="address" name="address" class="form-control"/></div>
</div>
<div class="row">
<div class="col-4">Date opening:</div>
<div class="col-8"><input type="datetime-local" id="date" name="date" class="form-control" required/></div>
</div>
<div class="row">
<div class="col-4">Max sushi:</div>
<div class="col-8"><input type="number" id="count" name="count" class="form-control"/></div>
</div>
<table class="table">
<thead>
<tr>
<th>
Sushi
</th>
<th>
Count
</th>
</tr>
</thead>
<tbody id="table-elements">
</tbody>
</table>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Save" class="btn btn-primary" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
const store = $('#store').val();
if (store) {
$.ajax({
method: "GET",
url: "/Home/GetStore",
data: { storeId: store },
success: function (result) {
$('#name').val(result.item1.storeName);
$('#address').val(result.item1.storeAdress);
$('#date').val(result.item1.openingDate);
$('#count').val(result.item1.packageMaxCount);
$('#table-elements').html(result.item2);
}
});
}
}
check();
$('#store').on('change', function () {
check();
});
</script>
}

View File

@ -17,16 +17,6 @@
aria-expanded="false" aria-label="Toggle navigation"> aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
<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="Create">Create</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Supply">Supply</a>
</li>
</ul>
</div>
</div> </div>
</nav> </nav>
</header> </header>

View File

@ -6,7 +6,6 @@
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"IPAddress": "http://localhost:5168/",
"IPAddress": "https://localhost:5168/",
"PasswordStore": "123" "PasswordStore": "123"
} }