Костыли помогают
This commit is contained in:
parent
0d19db0093
commit
a72b3a46ca
@ -20,5 +20,6 @@ namespace SewingDressesContracts.ViewModels
|
|||||||
[DisplayName("Вмещаемость")]
|
[DisplayName("Вмещаемость")]
|
||||||
public int MaxCount { get; set; }
|
public int MaxCount { get; set; }
|
||||||
public Dictionary<int, (IDressModel, int)> ShopDresses { get; set; } = new();
|
public Dictionary<int, (IDressModel, int)> ShopDresses { get; set; } = new();
|
||||||
|
public List<Tuple<string, int >> DressesCount { get;set;} = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,10 @@ namespace SewingDressesRestApi.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var shops = _logic.ReadList(null);
|
var shops = _logic.ReadList(null);
|
||||||
|
for (int i = 0; i < shops.Count; i++)
|
||||||
|
{
|
||||||
|
shops[i].DressesCount = shops[i].ShopDresses.Values.ToList().Select(x => (x.Item1.DressName, x.Item2).ToTuple()).ToList();
|
||||||
|
}
|
||||||
return shops;
|
return shops;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
52
SewingDresses/SewingDressesShopApp/ApiClient.cs
Normal file
52
SewingDresses/SewingDressesShopApp/ApiClient.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using SewingDressesContracts.ViewModels;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SewingDressesShopApp
|
||||||
|
{
|
||||||
|
public static class ApiClient
|
||||||
|
{
|
||||||
|
private static readonly HttpClient _client = new();
|
||||||
|
private static string password = string.Empty;
|
||||||
|
public static bool Access { get; private set; } = false;
|
||||||
|
public static void Connect(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
password = configuration["Password"];
|
||||||
|
_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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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 bool CheckPassword(string _password)
|
||||||
|
{
|
||||||
|
return Access = (_password == password);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SewingDressesShopApp.Models;
|
using SewingDressesShopApp.Models;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using SewingDressesContracts.ViewModels;
|
||||||
|
using SewingDressesContracts.SearchModels;
|
||||||
|
using SewingDressesContracts.BindingModels;
|
||||||
|
|
||||||
namespace SewingDressesShopApp.Controllers
|
namespace SewingDressesShopApp.Controllers
|
||||||
{
|
{
|
||||||
@ -15,18 +18,186 @@ namespace SewingDressesShopApp.Controllers
|
|||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return
|
||||||
|
View(ApiClient.GetRequest<List<ShopViewModel>>($"api/shop/getshoplist"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Enter()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void Enter(string password)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите пароль");
|
||||||
|
}
|
||||||
|
ApiClient.CheckPassword(password);
|
||||||
|
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
throw new Exception("Неправильный пароль");
|
||||||
|
}
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult Create()
|
||||||
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Privacy()
|
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Create(string name, string adress, DateTime dateOpen, int maxCount)
|
||||||
{
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(adress) || maxCount <= 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка в введенных данных");
|
||||||
|
}
|
||||||
|
ApiClient.PostRequest("api/shop/createshop", new ShopBindingModel
|
||||||
|
{
|
||||||
|
ShopName = name,
|
||||||
|
Adress = adress,
|
||||||
|
MaxCount = maxCount,
|
||||||
|
DateOpen = dateOpen
|
||||||
|
});
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult Delete()
|
||||||
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Shops = ApiClient.GetRequest<List<ShopViewModel>>("api/shop/getshoplist");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Delete(int shop)
|
||||||
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||||
|
}
|
||||||
|
ApiClient.PostRequest("api/shop/deleteshop", new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = shop,
|
||||||
|
Adress = "null",
|
||||||
|
DateOpen= DateTime.Now,
|
||||||
|
MaxCount = 1,
|
||||||
|
ShopName = "null",
|
||||||
|
ShopDresses = new()
|
||||||
|
}) ;
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult Update()
|
||||||
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Shops = ApiClient.GetRequest<List<ShopViewModel>>("api/shop/getshoplist");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Update(int shop, string name, string adress, DateTime dateOpen, int maxCount)
|
||||||
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(adress)
|
||||||
|
|| maxCount <= 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка в введенных данных");
|
||||||
|
}
|
||||||
|
ApiClient.PostRequest("api/shop/updateshop", new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = shop,
|
||||||
|
ShopName = name,
|
||||||
|
Adress = adress,
|
||||||
|
DateOpen = dateOpen,
|
||||||
|
MaxCount = maxCount,
|
||||||
|
});
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public Tuple<ShopViewModel, string>? GetShop(int shopId)
|
||||||
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||||
|
}
|
||||||
|
var result = ApiClient.GetRequest<Tuple<ShopViewModel, List<Tuple<string, int>>>>($"api/shop/getshop?shopid={shopId}");
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
string table = "";
|
||||||
|
result.Item1.ShopDresses.Clear();
|
||||||
|
for (int i = 0; i < result.Item2.Count; i++)
|
||||||
|
{
|
||||||
|
var dress = result.Item2[i].Item1;
|
||||||
|
var count = result.Item2[i].Item2;
|
||||||
|
table += "<tr>";
|
||||||
|
table += $"<td>{dress}</td>";
|
||||||
|
table += $"<td>{count}</td>";
|
||||||
|
table += "</tr>";
|
||||||
|
}
|
||||||
|
return Tuple.Create(result.Item1, table);
|
||||||
|
}
|
||||||
|
public IActionResult Supply()
|
||||||
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Shops = ApiClient.GetRequest<List<ShopViewModel>>("api/shop/getshoplist");
|
||||||
|
ViewBag.Dresses = ApiClient.GetRequest<List<DressViewModel>>("api/main/GetDressList");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Supply(int shopid, int dressid, int count)
|
||||||
|
{
|
||||||
|
if (ApiClient.Access == false)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||||
|
}
|
||||||
|
ApiClient.PostRequest("api/shop/makesupply", Tuple.Create(
|
||||||
|
new ShopSearchModel() { Id = shopid },
|
||||||
|
new DressViewModel() { Id = dressid },
|
||||||
|
count
|
||||||
|
));
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,13 @@
|
|||||||
|
using SewingDressesShopApp;
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
ApiClient.Connect(builder.Configuration);
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
@ -6,8 +6,14 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.29" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SewingDressesContracts\SewingDressesContracts.csproj" />
|
<ProjectReference Include="..\SewingDressesContracts\SewingDressesContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\SewingDressesRestApi\SewingDressesRestApi.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-4">Название:</div>
|
<div class="col-4">Название:</div>
|
||||||
<div class="col-8"><input type="text" id="shopname" name="shopname" /></div>
|
<div class="col-8"><input type="text" id="name" name="name" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-4">Адрес:</div>
|
<div class="col-4">Адрес:</div>
|
||||||
@ -48,10 +48,11 @@
|
|||||||
<input type="submit" value="Update" class="btn btn-success ps-5 pe-5" />
|
<input type="submit" value="Update" class="btn btn-success ps-5 pe-5" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<<script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script>
|
||||||
$('#shop').on('change', function () {
|
$('#shop').on('change', function () {
|
||||||
getData();
|
getData();
|
||||||
});
|
});
|
||||||
|
|
||||||
function getData() {
|
function getData() {
|
||||||
var shopId = $('#shop').val();
|
var shopId = $('#shop').val();
|
||||||
@ -61,18 +62,18 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (selectedShop) {
|
if (selectedShop) {
|
||||||
$("#shopname").val(selectedShop.shopname);
|
$("#name").val(selectedShop.shopName);
|
||||||
$("#dateopen").val(new Date(selectedShop.dateopen).toISOString().substring(0, 16));
|
$("#dateopen").val(new Date(selectedShop.dateOpen).toISOString().substring(0, 16));
|
||||||
$("#adress").val(selectedShop.adress);
|
$("#adress").val(selectedShop.adress);
|
||||||
$("#maxcount").val(selectedShop.maxcount);
|
$("#maxcount").val(selectedShop.maxCount);
|
||||||
fillTable(selectedShop.ShopDresses);
|
fillTable(selectedShop.dressesCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillTable(shopDresses) {
|
function fillTable(dressesCount) {
|
||||||
$("#dressTable").empty();
|
$("#dressTable").empty();
|
||||||
|
|
||||||
for (var dress in shopDresses)
|
for (var dress in dressesCount)
|
||||||
$("#dressTable").append('<tr><td>' + shopDresses[].item1 + '</td><td>' + shopDresses[dress].item2 + '</td></tr>');
|
$("#dressTable").append('<tr><td>' + dressesCount[dress].item1 + '</td><td>' + dressesCount[dress].item2 + '</td></tr>');
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
@ -3,18 +3,15 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>@ViewData["Title"] - ShopApp</title>
|
<title>@ViewData["Title"] - SewingDressesShopsApp</title>
|
||||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||||
<link rel="stylesheet" href="~/css/site.css" />
|
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
|
||||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
|
||||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">SewingDressesShopApp</a>
|
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">SewingDressesShopsApp</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
<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">
|
aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
@ -40,7 +37,7 @@
|
|||||||
|
|
||||||
<footer class="border-top footer text-muted">
|
<footer class="border-top footer text-muted">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
© 2024 - SewingDressesShopApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
© 2024 - SewingDressesShopsApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
@ -5,5 +5,7 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"IPAddress": "http://localhost:5299/",
|
||||||
|
"Password": "bober"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user