Merge branch 'lab5_hard' into lab6_hard

This commit is contained in:
prodigygirl 2023-05-05 10:38:22 +04:00
commit 31b2f3cde3
5 changed files with 13 additions and 38 deletions

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace FurnitureAssemblyContracts.ViewModels
@ -17,9 +18,11 @@ namespace FurnitureAssemblyContracts.ViewModels
public string Address { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime DateOpening { get; set; }
[JsonIgnore]
public Dictionary<int, (IFurnitureModel, int)> Furnitures { get; set; } = new();
[DisplayName("Вместимость")]
public int MaxCount { get; set; }
public List<FurnitureCountViewModel>? FurnituresCount { get; set; } = new();
}
}

View File

@ -1,22 +0,0 @@
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; }
}
}

View File

@ -36,7 +36,7 @@ namespace FurnitureAssemblyRestApi.Controllers
}
[HttpGet]
public ShopViewModelWeb? GetShop(int shopId)
public ShopViewModel? GetShop(int shopId)
{
try
{
@ -49,16 +49,10 @@ namespace FurnitureAssemblyRestApi.Controllers
});
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;
shop.FurnituresCount = shop.Furnitures.Select(x => x.Value)
.Select(x => new FurnitureCountViewModel { furniture = x.Item1.FurnitureName, Count = x.Item2 }).ToList();
return shop;
}
catch (Exception ex)
{

View File

@ -139,9 +139,9 @@ namespace FurnitureAssemblyShopWorkApp.Controllers
Response.Redirect("Index");
}
[HttpGet]
public ShopViewModelWeb? GetShop(int shopId)
public ShopViewModel? GetShop(int shopId)
{
return APIClient.GetRequest<ShopViewModelWeb>($"api/shop/getshop?shopId={shopId}");
return APIClient.GetRequest<ShopViewModel>($"api/shop/getshop?shopId={shopId}");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

View File

@ -56,8 +56,8 @@
$("#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);
$("#count").val(result.maxCount);
fillTable(result.furnituresCount);
}
});
}