Последняя доработка, связанная с обновлением магазина
This commit is contained in:
parent
01f491f51f
commit
4d10a7681b
@ -0,0 +1,15 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.ViewModels
|
||||
{
|
||||
public class FurnitureCountViewModel
|
||||
{
|
||||
public string furniture { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModelWeb
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название магазина")]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
[DisplayName("Адрес магазина")]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime DateOpening { get; set; }
|
||||
public List<FurnitureCountViewModel>? Furnitures { get; set; } = new();
|
||||
public int MaxCount { get; set; }
|
||||
}
|
||||
}
|
@ -160,8 +160,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
context.SaveChanges();
|
||||
shop.UpdateFurnitures(context, model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContarcts;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDatabaseImplement.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace FurnitureAssemblyRestApi.Controllers
|
||||
@ -36,14 +36,29 @@ namespace FurnitureAssemblyRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ShopViewModel? GetShop(int shopId)
|
||||
public ShopViewModelWeb? GetShop(int shopId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _shop.ReadElement(new ShopSearchModel
|
||||
// получаем обычную ShopViewModel из бизнес-логики, а затем преобразуем в новую модель для передачи в "стороннее" приложение - на клиент
|
||||
// главное отличие от предыдущей модели в способе передачи изделий - теперь они представлены в виде списка сериализуемых моделей FurnitureCountViewModel
|
||||
// данное решение необходимо для корректной сериализации изделий и их количества в магазине
|
||||
var shop = _shop.ReadElement(new ShopSearchModel
|
||||
{
|
||||
Id = shopId
|
||||
});
|
||||
if (shop == null)
|
||||
return null;
|
||||
var shopWeb = new ShopViewModelWeb
|
||||
{
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
DateOpening = shop.DateOpening,
|
||||
Furnitures = shop.Furnitures.Select(x => x.Value).Select(x => new FurnitureCountViewModel { furniture = x.Item1.FurnitureName, Count = x.Item2 }).ToList(),
|
||||
MaxCount = shop.MaxCount
|
||||
};
|
||||
return shopWeb;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -121,11 +121,28 @@ namespace FurnitureAssemblyShopWorkApp.Controllers
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpGet]
|
||||
public ShopViewModel GetShop()
|
||||
public IActionResult Replenishment()
|
||||
{
|
||||
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>("api/shop/getshoplist");
|
||||
ViewBag.Furnitures = APIClient.GetRequest<List<FurnitureViewModel>>("api/main/getfurniturelist");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void Replenishment(int shop, int furniture, int count)
|
||||
{
|
||||
if (!APIClient.isAuth)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
|
||||
APIClient.PostRequest($"api/shop/addfurniturestoshop", ( new ShopBindingModel { Id = shop }, new FurnitureBindingModel {Id =furniture}, count));
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpGet]
|
||||
public ShopViewModelWeb? GetShop(int shopId)
|
||||
{
|
||||
return APIClient.GetRequest<ShopViewModelWeb>($"api/shop/getshop?shopId={shopId}");
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
|
@ -16,6 +16,8 @@
|
||||
<p>
|
||||
<a asp-action="Create">Создать магазин</a>
|
||||
<a asp-action="Delete">Удалить магазин</a>
|
||||
<a asp-action="Update">Редактировать магазин</a>
|
||||
<a asp-action="Replenishment">Пополнить магазин</a>
|
||||
</p>
|
||||
|
||||
<table class="table">
|
||||
|
@ -0,0 +1,27 @@
|
||||
@{
|
||||
ViewData["Title"] = "Replenishment";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Пополнение магазина</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Название магазина:</div>
|
||||
<div class="col-8">
|
||||
<select id="shop" name="shop" class="form-control" asp-items="@(new SelectList(@ViewBag.Shops,"Id", "ShopName"))"></select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Изделие:</div>
|
||||
<div class="col-8">
|
||||
<select id="furniture" name="furniture" class="form-control" asp-items="@(new SelectList(@ViewBag.Furnitures,"Id", "FurnitureName"))"></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="col-4"><input type="submit" value="Пополнить" class="btn
|
||||
btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -0,0 +1,72 @@
|
||||
@{
|
||||
ViewData["Title"] = "Update";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Редактирование магазина</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Магазин:</div>
|
||||
<div class="col-8">
|
||||
<select id="shop" name="shop" onchange="getData()" class="form-control" asp-items="@(new SelectList(@ViewBag.Shops,"Id", "ShopName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8"><input type="text" name="shopName" id="shopName"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Дата открытия:</div>
|
||||
<div class="col-8"><input type="datetime-local" id="dateOpening" name="dateOpening"/></div>
|
||||
<div class="row">
|
||||
<div class="col-4">Адрес:</div>
|
||||
<div class="col-8"><input type="text" id="address" name="address"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Вместимость:</div>
|
||||
<div class="col-8"><input type="number" id="count" name="count"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Изделия в магазине:</div>
|
||||
<div class="col-8">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Изделие</th>
|
||||
<th>Количество</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="furnitures">
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4"><input type="submit" value="Принять" class="btn
|
||||
btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
function getData() {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetShop",
|
||||
data: { shopId: $('#shop').val()},
|
||||
success: function (result) {
|
||||
$("#shopName").val(result.shopName);
|
||||
$("#dateOpening").val(new Date(result.dateOpening).toISOString().substring(0, 16));
|
||||
$("#address").val(result.address);
|
||||
$("#count").val(result.maxCount);
|
||||
fillTable(result.furnitures);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fillTable(furnitures) {
|
||||
$("#furnitures").empty();
|
||||
|
||||
for(var i = 0; i < furnitures.length; i++)
|
||||
$("#furnitures").append('<tr><td>' + furnitures[i].furniture +
|
||||
'</td><td>' + furnitures[i].count + '</td></tr>');
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user