доне
This commit is contained in:
parent
5ed879f53e
commit
e90f31fcd3
@ -10,14 +10,16 @@ namespace SushiBarClientApp
|
||||
public class APIClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
public static ClientViewModel? Client { get; set; } = null;
|
||||
|
||||
public static string? Password { get; set; }
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
_client.DefaultRequestHeaders.Accept.Add(new
|
||||
MediaTypeWithQualityHeaderValue("application/json"));
|
||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.GetAsync(requestUrl);
|
||||
@ -31,12 +33,24 @@ namespace SushiBarClientApp
|
||||
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 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 DeleteRequest(string requestUrl)
|
||||
{
|
||||
var response = _client.DeleteAsync(requestUrl);
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
@ -44,5 +58,5 @@ namespace SushiBarClientApp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,143 +11,142 @@ namespace SushiBarClientApp.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
if (APIClient.Password == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return
|
||||
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={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/client/updatedata", new
|
||||
ClientBindingModel
|
||||
{
|
||||
Id = APIClient.Client.Id,
|
||||
ClientFIO = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
APIClient.Client.ClientFIO = fio;
|
||||
APIClient.Client.Email = login;
|
||||
APIClient.Client.Password = password;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None,
|
||||
NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel
|
||||
{
|
||||
RequestId =
|
||||
Activity.Current?.Id ?? HttpContext.TraceIdentifier
|
||||
});
|
||||
return View(APIClient.GetRequest<List<ShopViewModel>>($"api/shop/getshoplist?password={APIClient.Password}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Enter(string login, string password)
|
||||
public void Enter(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password))
|
||||
bool resout = APIClient.GetRequest<bool>($"/api/shop/authentication?password={password}");
|
||||
if (!resout)
|
||||
{
|
||||
throw new Exception("Введите логин и пароль");
|
||||
}
|
||||
APIClient.Client =
|
||||
APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void Register(string login, string password, string fio)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIClient.PostRequest("api/client/register", new
|
||||
ClientBindingModel
|
||||
{
|
||||
ClientFIO = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
Response.Redirect("../Home/Enter");
|
||||
return;
|
||||
}
|
||||
APIClient.Password = password;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewBag.Sushis =
|
||||
APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
|
||||
return View();
|
||||
if (APIClient.Password == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View("Shop");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(int sushi, int count)
|
||||
public void Create(int id, string shopname, string adress, DateTime openingdate, int maxcount)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
if (string.IsNullOrEmpty(shopname) || string.IsNullOrEmpty(adress))
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
throw new Exception("Название или адрес не может быть пустым");
|
||||
}
|
||||
if (count <= 0)
|
||||
if (openingdate == default(DateTime))
|
||||
{
|
||||
throw new Exception("Количество и сумма должны быть больше 0");
|
||||
throw new Exception("Дата открытия не может быть пустой");
|
||||
}
|
||||
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
|
||||
|
||||
APIClient.PostRequest($"api/shop/createshop?password={APIClient.Password}", new ShopBindingModel
|
||||
{
|
||||
ClientId = APIClient.Client.Id,
|
||||
SushiId = sushi,
|
||||
Count = count,
|
||||
Sum = Calc(count, sushi)
|
||||
Id = id,
|
||||
ShopName = shopname,
|
||||
Adress = adress,
|
||||
OpeningDate = openingdate,
|
||||
SushiMaxCount = maxcount
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpPost]
|
||||
public double Calc(int count, int sushi)
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Update(int Id)
|
||||
{
|
||||
var prod =
|
||||
APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiId={sushi}"
|
||||
);
|
||||
return count * (prod?.Price ?? 1);
|
||||
if (APIClient.Password == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View("Shop", APIClient.GetRequest<ShopSushiViewModel>($"api/shop/getshop?shopId={Id}&password={APIClient.Password}"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(int id, string shopname, string adress, DateTime openingdate, int maxcount)
|
||||
{
|
||||
if (string.IsNullOrEmpty(shopname) || string.IsNullOrEmpty(adress))
|
||||
{
|
||||
throw new Exception("Название или адрес не может быть пустым");
|
||||
}
|
||||
if (openingdate == default(DateTime))
|
||||
{
|
||||
throw new Exception("Дата открытия не может быть пустой");
|
||||
}
|
||||
APIClient.PostRequest($"api/shop/updateshop?password={APIClient.Password}", new ShopBindingModel
|
||||
{
|
||||
Id = id,
|
||||
ShopName = shopname,
|
||||
Adress = adress,
|
||||
OpeningDate = openingdate,
|
||||
SushiMaxCount = maxcount
|
||||
});
|
||||
Response.Redirect("../Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int Id)
|
||||
{
|
||||
APIClient.DeleteRequest($"api/shop/deleteshop?shopId={Id}&password={APIClient.Password}");
|
||||
Response.Redirect("../Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Supply()
|
||||
{
|
||||
if (APIClient.Password == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>($"api/shop/getshoplist?password={APIClient.Password}");
|
||||
ViewBag.Sushis = APIClient.GetRequest<List<SushiViewModel>>($"api/main/getsushilist");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Supply(int shop, int sushi, int count)
|
||||
{
|
||||
APIClient.PostRequest($"api/shop/makesypply?password={APIClient.Password}", new SupplyBindingModel
|
||||
{
|
||||
ShopId = shop,
|
||||
SushiId = sushi,
|
||||
Count = count
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,21 @@
|
||||
@using SushiBarContracts.ViewModels
|
||||
|
||||
@model List<OrderViewModel>
|
||||
@model List<ShopViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Заказы</h1>
|
||||
<h1 class="display-4">Магазины</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="text-center ">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
|
||||
<p>
|
||||
<a asp-action="Create">Создать заказ</a>
|
||||
<a asp-action="Create">Создать магазин</a>
|
||||
</p>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -29,19 +23,19 @@
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Суши
|
||||
Название
|
||||
</th>
|
||||
<th>
|
||||
Дата создания
|
||||
Адрес
|
||||
</th>
|
||||
<th>
|
||||
Количество
|
||||
Дата открытия
|
||||
</th>
|
||||
<th>
|
||||
Сумма
|
||||
Максимальная вместимость
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -53,23 +47,22 @@
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.SushiName)
|
||||
@Html.DisplayFor(modelItem => item.ShopName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DateCreate)
|
||||
@Html.DisplayFor(modelItem => item.Adress)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Count)
|
||||
@Html.DisplayFor(modelItem => item.OpeningDate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Sum)
|
||||
@Html.DisplayFor(modelItem => item.SushiMaxCount)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Status)
|
||||
<a class="btn btn-primary" asp-action="Update" asp-route-Id="@(item.Id)" role="button">Изменить</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
74
SushiBar/SushiBarClientApp/Views/Home/Shop.cshtml
Normal file
74
SushiBar/SushiBarClientApp/Views/Home/Shop.cshtml
Normal file
@ -0,0 +1,74 @@
|
||||
@using SushiBarDataModels.Models;
|
||||
@using SushiBarContracts.ViewModels;
|
||||
@model ShopSushiViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Shop";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h2 class="display-4">Создание магазина</h2>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h2 class="display-4">Изменение магазина</h2>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Название</label>
|
||||
<input type="text" class="form-control" name="shopname" id="shopname" value="@(Model==null ? "" : Model.Shop?.ShopName)" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Адрес</label>
|
||||
<input type="text" class="form-control" name="adress" id="adress" value="@(Model==null ? "" : Model.Shop?.Adress)" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="startDate">Дата открытия</label>
|
||||
<input class="form-control" type="date" name="openingdate" id="openingdate" value="@(Model==null ? "" : Model.Shop?.OpeningDate.ToString("yyyy-MM-dd"))" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Вместимость</label>
|
||||
<input type="number" min="0" step="1" pattern="[0-9]" class="form-control" name="maxcount" id="maxcount" value="@(Model==null ? "" : Model.Shop?.SushiMaxCount)" />
|
||||
</div>
|
||||
<div class="mb-3 ">
|
||||
<input class="btn btn-primary" type="submit" value="Сохранить">
|
||||
@{
|
||||
if (Model != null && Model.Shop != null)
|
||||
{
|
||||
<input class="btn btn-danger" asp-action="Delete" type="submit" value="Удалить" asp-route-Id="@(Model==null ? 0 : Model.Shop.Id.ToString())">
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
@{
|
||||
if (Model != null && Model.Shop != null)
|
||||
{
|
||||
<div>
|
||||
<h6>Содержимое магазина</h6>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
<th>Количество</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.ShopSushi)
|
||||
{
|
||||
<tr>
|
||||
<td>@Html.DisplayFor(modelItem => item.Value.Sushi.SushiName)</td>
|
||||
<td>@Html.DisplayFor(modelItem => item.Value.Count)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
}
|
||||
}
|
22
SushiBar/SushiBarClientApp/Views/Home/Supply.cshtml
Normal file
22
SushiBar/SushiBarClientApp/Views/Home/Supply.cshtml
Normal file
@ -0,0 +1,22 @@
|
||||
@{
|
||||
ViewData["Title"] = "Supply";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание поставки</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Магазин</label>
|
||||
<select class="form-select form-select-lg" id="shop" name="shop" asp-items="@(new SelectList(@ViewBag.Shops,"Id", "ShopName"))"></select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Пицца</label>
|
||||
<select class="form-select form-select-lg" id="sushi" name="sushi" asp-items="@(new SelectList(@ViewBag.Sushis,"Id", "SushiName"))"></select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Колличество</label>
|
||||
<input type="number" min="0" step="1" pattern="[0-9]" class="form-control" name="count" id="count">
|
||||
</div>
|
||||
<input class="btn btn-success" type="submit" value="Создать поставку">
|
||||
<a class="btn btn-primary" href="./Index" role="button">Отмена</a>
|
||||
</form>
|
@ -14,24 +14,18 @@
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Суши-Бар</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">PizzeriaShopsApi</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
|
||||
<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="Index">Заказы</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
|
||||
</li>
|
||||
<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="Enter">Вход</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Supply">Поставка</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -46,7 +40,7 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2024 - SushiBarClientApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
© 2024 - SushiBarShopApp - <a asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
|
14
SushiBar/SushiBarContracts/ViewModels/ShopSushiViewModel.cs
Normal file
14
SushiBar/SushiBarContracts/ViewModels/ShopSushiViewModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class ShopSushiViewModel
|
||||
{
|
||||
public ShopViewModel Shop { get; set; } = new();
|
||||
public Dictionary<int, SushiCount> ShopSushi { get; set; } = new();
|
||||
}
|
||||
}
|
14
SushiBar/SushiBarContracts/ViewModels/SushiCount.cs
Normal file
14
SushiBar/SushiBarContracts/ViewModels/SushiCount.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class SushiCount
|
||||
{
|
||||
public SushiViewModel Sushi { get; set; }
|
||||
public int Count { get; set; } = new();
|
||||
}
|
||||
}
|
@ -12,13 +12,8 @@ using SushiBarDatabaseImplement;
|
||||
namespace SushiBarDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SushiBarDatabase))]
|
||||
<<<<<<<< HEAD:SushiBar/SushiBarDatabaseImplement/Migrations/20240420142132_InitialCreate.Designer.cs
|
||||
[Migration("20240420142132_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
========
|
||||
[Migration("20240424121819_InitCreate")]
|
||||
[Migration("20240508053719_InitCreate")]
|
||||
partial class InitCreate
|
||||
>>>>>>>> Lab_4_Hard:SushiBar/SushiBarDatabaseImplement/Migrations/20240424121819_InitCreate.Designer.cs
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
@ -199,11 +199,10 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
name: "SushiComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
<<<<<<<< HEAD:SushiBar/SushiBarDatabaseImplement/Migrations/20240420142132_InitialCreate.cs
|
||||
name: "Clients");
|
||||
========
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
>>>>>>>> Lab_4_Hard:SushiBar/SushiBarDatabaseImplement/Migrations/20240424121819_InitCreate.cs
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
12
SushiBar/SushiBarRestApi/APIConfig.cs
Normal file
12
SushiBar/SushiBarRestApi/APIConfig.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace SushiBarRestApi
|
||||
{
|
||||
public class APIConfig
|
||||
{
|
||||
public static string? ShopPassword;
|
||||
|
||||
public static void LoadData(IConfiguration configuration)
|
||||
{
|
||||
ShopPassword = configuration["ShopAPIPassword"];
|
||||
}
|
||||
}
|
||||
}
|
156
SushiBar/SushiBarRestApi/Controllers/ShopController.cs
Normal file
156
SushiBar/SushiBarRestApi/Controllers/ShopController.cs
Normal file
@ -0,0 +1,156 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ShopController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
|
||||
public ShopController(ILogger<ShopController> logger, IShopLogic shopLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_shopLogic = shopLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public bool Authentication(string password)
|
||||
{
|
||||
return CheckPassword(password);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ShopViewModel>? GetShopList(string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
return _shopLogic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ShopSushiViewModel? GetShop(int shopId, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
var shop = _shopLogic.ReadElement(new ShopSearchModel { Id = shopId });
|
||||
return new ShopSushiViewModel
|
||||
{
|
||||
Shop = shop,
|
||||
ShopSushi = shop.ShopSushis.ToDictionary(x => x.Key, x => new SushiCount
|
||||
{
|
||||
Sushi = new SushiViewModel()
|
||||
{
|
||||
Id = x.Value.Item1.Id,
|
||||
SushiName = x.Value.Item1.SushiName,
|
||||
SushiComponents = x.Value.Item1.SushiComponents,
|
||||
Price = x.Value.Item1.Price,
|
||||
},
|
||||
Count = x.Value.Item2
|
||||
})
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateShop(ShopBindingModel model, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_shopLogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateShop(ShopBindingModel model, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_shopLogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteShop(int shopId, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_shopLogic.Delete(new ShopBindingModel { Id = shopId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void MakeSypply(SupplyBindingModel model, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_shopLogic.MakeSupply(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания поставки в магазин");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckPassword(string password)
|
||||
{
|
||||
return APIConfig.ShopPassword == password;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,17 +5,20 @@ using SushiBarBusinessLogic.BusinessLogics;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarDatabaseImplement.Implements;
|
||||
using SushiBarRestApi;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IShopStorage, ShopStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<ISushiStorage, SushiStorage>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<ISushiLogic, SushiLogic>();
|
||||
builder.Services.AddTransient<IShopLogic, ShopLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
@ -30,6 +33,7 @@ builder.Services.AddSwaggerGen(c =>
|
||||
});
|
||||
});
|
||||
var app = builder.Build();
|
||||
APIConfig.LoadData(builder.Configuration);
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
|
@ -5,5 +5,7 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"ShopAPIPassword": "123456"
|
||||
}
|
||||
|
8
SushiBar/SushiBarView/FormMain.Designer.cs
generated
8
SushiBar/SushiBarView/FormMain.Designer.cs
generated
@ -39,7 +39,7 @@
|
||||
sushiToolStripMenuItemToolStripMenuItem = new ToolStripMenuItem();
|
||||
отчётыToolStripMenuItem = new ToolStripMenuItem();
|
||||
componentsToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
componentSushiToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
//componentSushiToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
ordersToolStripMenuItem = new ToolStripMenuItem();
|
||||
dataGridView = new DataGridView();
|
||||
ClientToolStripMenuItem = new ToolStripMenuItem();
|
||||
@ -181,7 +181,7 @@
|
||||
//
|
||||
// отчётыToolStripMenuItem
|
||||
//
|
||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem1, componentSushiToolStripMenuItem1, ordersToolStripMenuItem });
|
||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem1, ordersToolStripMenuItem });
|
||||
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
||||
отчётыToolStripMenuItem.Size = new Size(60, 20);
|
||||
отчётыToolStripMenuItem.Text = "Отчёты";
|
||||
@ -211,14 +211,14 @@
|
||||
//
|
||||
// сушиСИнгрToolStripMenuItem
|
||||
//
|
||||
componentSushiToolStripMenuItem1.Name = "componentSushiToolStripMenuItem1";
|
||||
/* componentSushiToolStripMenuItem1.Name = "componentSushiToolStripMenuItem1";
|
||||
componentSushiToolStripMenuItem1.Size = new Size(201, 22);
|
||||
componentSushiToolStripMenuItem1.Text = "Суши с компонентами";
|
||||
componentSushiToolStripMenuItem1.Click += ComponentSushiToolStripMenuItem_Click;
|
||||
сушиСИнгрToolStripMenuItem.Name = "сушиСИнгрToolStripMenuItem";
|
||||
сушиСИнгрToolStripMenuItem.Size = new Size(201, 22);
|
||||
сушиСИнгрToolStripMenuItem.Text = "Суши с компонентами";
|
||||
сушиСИнгрToolStripMenuItem.Click += ComponentSushiToolStripMenuItem_Click;
|
||||
сушиСИнгрToolStripMenuItem.Click += ComponentSushiToolStripMenuItem_Click;*/
|
||||
//
|
||||
// ordersToolStripMenuItem
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user