Minhasapov R.H. LabWork05_Hard #13

Closed
safgerd wants to merge 14 commits from LabWork05_Hard into LabWork04_Hard
6 changed files with 82 additions and 57 deletions
Showing only changes of commit 53817233dc - Show all commits

View File

@ -17,7 +17,7 @@ namespace AutomobilePlantContracts.BindingModels
public DateTime OpeningDate { get; set; }
public Dictionary<int, (ICarModel, int)> ShopCars { get; set; }
public Dictionary<int, (ICarModel, int)> ShopCars { get; set; } = new();
public int MaxCountCars { get; set; }
}
}

View File

@ -51,7 +51,7 @@ namespace AutomobilePlantRestApi.Controllers
carCount.Add(new Tuple<string, int>(car.Value.Item1.CarName, car.Value.Item2));
}
shop = new()
shop = new ShopViewModel()
{
Id = shop.Id,
Name = shop.Name,

View File

@ -124,8 +124,32 @@ namespace AutomobilePlantShopApp.Controllers
Response.Redirect("Index");
}
[HttpGet]
public ShopViewModel? GetShop(int shopId)
{
return APIClient.GetRequest<ShopViewModel>($"api/shop/getshop?shopId={shopId}");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Supply()
{
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>("api/shop/getshoplist");
ViewBag.Cars = APIClient.GetRequest<List<CarViewModel>>("api/main/getcarlist");
return View();
}
[HttpPost]
public void Supply(int shopId, int carId, int count)
{
if (!APIClient.isAuth)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest($"api/shop/supplycarstoshop", (new ShopSearchModel { Id = shopId }, new CarBindingModel { Id = carId }, 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 });

View File

@ -6,6 +6,7 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())

View File

@ -10,48 +10,48 @@
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p >
<a class="text-decoration-none me-3 text-black h5" asp-action="Create">Создать магазин</a>
<a class="text-decoration-none me-3 text-black h5" asp-action="Update">Изменить магазин</a>
<a class="text-decoration-none me-3 text-black h5" asp-action="Supply">Пополнить магазин</a>
<a class="text-decoration-none text-black h5" asp-action="Delete">Удалить магазин</a>
</p>
<p >
<a class="text-decoration-none me-3 text-black h5" asp-action="Create">Создать магазин</a>
<a class="text-decoration-none me-3 text-black h5" asp-action="Update">Изменить магазин</a>
<a class="text-decoration-none me-3 text-black h5" asp-action="Supply">Пополнить магазин</a>
<a class="text-decoration-none text-black h5" asp-action="Delete">Удалить магазин</a>
</p>
<table class="table">
<thead>
<tr>
<th>Номер</th>
<th>Название</th>
<th>Адрес</th>
<th>Дата открытия</th>
<th>Макс. авто</th>
</tr>
</thead>
<tbody>
<table class="table">
<thead>
<tr>
<th>Номер</th>
<th>Название</th>
<th>Адрес</th>
<th>Дата открытия</th>
<th>Макс. авто</th>
</tr>
</thead>
<tbody>
@foreach (var shop in Model)
{
<tr>
<td>
<tr>
<td>
@Html.DisplayFor(modelItem => shop.Id)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => shop.Name)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => shop.Address)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => shop.OpeningDate)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => shop.MaxCountCars)
</td>
</tr>
</td>
</tr>
}
</tbody>
</table>
</tbody>
</table>
}
</div>

View File

@ -29,24 +29,24 @@
<div class="col-4">Макс. авто:</div>
<div class="col-8"><input type="number" id="count" name="count" /></div>
</div>
<div class="row mb-3">
<div class="col-4">Авто в магазине:</div>
<div class="col-8">
<table class="table">
<thead>
<tr>
<th>Автомобиль</th>
<th>Количество</th>
</tr>
</thead>
<tbody id="carcount">
</tbody>
</table>
</div>
</div>
<div class="text-center ">
<input type="submit" value="Принять" class="btn btn-success ps-5 pe-5" />
<div class="row mb-3">
<div class="col-4">Авто в магазине:</div>
<div class="col-8">
<table class="table">
<thead>
<tr>
<th>Автомобиль</th>
<th>Количество</th>
</tr>
</thead>
<tbody id="carсount">
</tbody>
</table>
</div>
</div>
<div class="text-center ">
<input type="submit" value="Принять" class="btn btn-success ps-5 pe-5" />
</div>
</form>
<script>
@ -57,11 +57,11 @@
data: { shopId: $('#shop').val()},
success: function (result) {
console.log(result)
$("#name").val(result.name);
$("#openingDate").val(new Date(result.openingDate).toISOString().substring(0, 16));
$("#address").val(result.address);
$("#count").val(result.maxCountCars);
fillTable(result.carCount);
$("#name").val(result.Name);
$("#openingDate").val(new Date(result.OpeningDate).toISOString().substring(0, 16));
$("#address").val(result.Address);
$("#count").val(result.MaxCountCars);
fillTable(result.CarCount);
}
});
}