Изменение для сериализации магазина
This commit is contained in:
parent
8428da853c
commit
8f672d8bd7
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FurnitureAssemblyContracts.ViewModels
|
namespace FurnitureAssemblyContracts.ViewModels
|
||||||
@ -17,9 +18,11 @@ namespace FurnitureAssemblyContracts.ViewModels
|
|||||||
public string Address { get; set; } = string.Empty;
|
public string Address { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата открытия")]
|
[DisplayName("Дата открытия")]
|
||||||
public DateTime DateOpening { get; set; }
|
public DateTime DateOpening { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
public Dictionary<int, (IFurnitureModel, int)> Furnitures { get; set; } = new();
|
public Dictionary<int, (IFurnitureModel, int)> Furnitures { get; set; } = new();
|
||||||
[DisplayName("Вместимость")]
|
[DisplayName("Вместимость")]
|
||||||
public int MaxCount { get; set; }
|
public int MaxCount { get; set; }
|
||||||
|
|
||||||
|
public List<FurnitureCountViewModel>? FurnituresCount { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -36,7 +36,7 @@ namespace FurnitureAssemblyRestApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ShopViewModelWeb? GetShop(int shopId)
|
public ShopViewModel? GetShop(int shopId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -49,16 +49,10 @@ namespace FurnitureAssemblyRestApi.Controllers
|
|||||||
});
|
});
|
||||||
if (shop == null)
|
if (shop == null)
|
||||||
return null;
|
return null;
|
||||||
var shopWeb = new ShopViewModelWeb
|
|
||||||
{
|
shop.FurnituresCount = shop.Furnitures.Select(x => x.Value)
|
||||||
Id = shop.Id,
|
.Select(x => new FurnitureCountViewModel { furniture = x.Item1.FurnitureName, Count = x.Item2 }).ToList();
|
||||||
ShopName = shop.ShopName,
|
return shop;
|
||||||
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -139,9 +139,9 @@ namespace FurnitureAssemblyShopWorkApp.Controllers
|
|||||||
Response.Redirect("Index");
|
Response.Redirect("Index");
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[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)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
|
@ -56,8 +56,8 @@
|
|||||||
$("#shopName").val(result.shopName);
|
$("#shopName").val(result.shopName);
|
||||||
$("#dateOpening").val(new Date(result.dateOpening).toISOString().substring(0, 16));
|
$("#dateOpening").val(new Date(result.dateOpening).toISOString().substring(0, 16));
|
||||||
$("#address").val(result.address);
|
$("#address").val(result.address);
|
||||||
$("#count").val(result.maxCount);
|
$("#count").val(result.maxCount);
|
||||||
fillTable(result.furnitures);
|
fillTable(result.furnituresCount);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user