Добавлена модель магазина в реализацию хранилища на списках. Добавлено поле максимального кол-ва товара.
This commit is contained in:
parent
faa36dadf2
commit
cfb587fb59
@ -5,13 +5,10 @@ namespace SecuritySystemContracts.BindingModels
|
|||||||
public class ShopBindingModel : IShopModel
|
public class ShopBindingModel : IShopModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string Address { get; set; } = string.Empty;
|
public string Address { get; set; } = string.Empty;
|
||||||
|
|
||||||
public DateTime OpeningDate { get; set; }
|
public DateTime OpeningDate { get; set; }
|
||||||
|
public int MaxSecuresCount { get; set; }
|
||||||
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; set; } = new();
|
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ namespace SecuritySystemContracts.ViewModels
|
|||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
[DisplayName("Адрес")]
|
[DisplayName("Адрес")]
|
||||||
public string Address { get; set; } = string.Empty;
|
public string Address { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Макс. кол-во товара")]
|
||||||
|
public int MaxSecuresCount { get; set; }
|
||||||
[DisplayName("Дата открытия")]
|
[DisplayName("Дата открытия")]
|
||||||
public DateTime OpeningDate { get; set; }
|
public DateTime OpeningDate { get; set; }
|
||||||
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; set; } = new();
|
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; set; } = new();
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
string Name { get; }
|
string Name { get; }
|
||||||
string Address { get; }
|
string Address { get; }
|
||||||
DateTime OpeningDate { get; }
|
DateTime OpeningDate { get; }
|
||||||
|
int MaxSecuresCount { get; }
|
||||||
Dictionary<int, (ISecureModel, int)> ShopSecures { get; }
|
Dictionary<int, (ISecureModel, int)> ShopSecures { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
111
SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs
Normal file
111
SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
using SecuritySystemDataModels.Models;
|
||||||
|
using SecuritySystemFileImplement;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AutomobilePlantFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
public string Address { get; private set; } = string.Empty;
|
||||||
|
public int MaxSecuresCount { get; private set; }
|
||||||
|
public DateTime OpeningDate { get; private set; }
|
||||||
|
public Dictionary<int, int> Secures { get; private set; } = new();
|
||||||
|
private Dictionary<int, (ISecureModel, int)>? _shopSecures = null;
|
||||||
|
public Dictionary<int, (ISecureModel, int)> ShopSecures
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopSecures == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_shopSecures = Secures.ToDictionary(
|
||||||
|
x => x.Key,
|
||||||
|
y => ((source.Secures.FirstOrDefault(z => z.Id == y.Key) as ISecureModel)!, y.Value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _shopSecures;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
Address = model.Address,
|
||||||
|
MaxSecuresCount = model.MaxSecuresCount,
|
||||||
|
OpeningDate = model.OpeningDate,
|
||||||
|
Secures = model.ShopSecures.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
Name = element.Element("Name")!.Value,
|
||||||
|
Address = element.Element("Address")!.Value,
|
||||||
|
MaxSecuresCount = Convert.ToInt32(element.Element("MaxSecuresCount")!.Value),
|
||||||
|
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||||
|
Secures = element.Element("ShopSecures")!.Elements("ShopSecure").ToDictionary(
|
||||||
|
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||||
|
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Name = model.Name;
|
||||||
|
Address = model.Address;
|
||||||
|
MaxSecuresCount = model.MaxSecuresCount;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
if (model.ShopSecures.Count > 0)
|
||||||
|
{
|
||||||
|
Secures = model.ShopSecures.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_shopSecures = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Address = Address,
|
||||||
|
MaxSecuresCount = MaxSecuresCount,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopSecures = ShopSecures,
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new(
|
||||||
|
"Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("Name", Name),
|
||||||
|
new XElement("Address", Address),
|
||||||
|
new XElement("MaxSecuresCount", MaxSecuresCount),
|
||||||
|
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||||
|
new XElement("ShopSecures", Secures.Select(x =>
|
||||||
|
new XElement("ShopSecure",
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
@ -10,8 +10,8 @@ namespace SecuritySystemListImplement.Models
|
|||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
public string Address { get; private set; } = string.Empty;
|
public string Address { get; private set; } = string.Empty;
|
||||||
public DateTime OpeningDate { get; private set; }
|
public DateTime OpeningDate { get; private set; }
|
||||||
|
public int MaxSecuresCount { get; private set; }
|
||||||
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; private set; } = new();
|
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; private set; } = new();
|
||||||
|
|
||||||
public static Shop? Create(ShopBindingModel model)
|
public static Shop? Create(ShopBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -25,6 +25,7 @@ namespace SecuritySystemListImplement.Models
|
|||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
Address = model.Address,
|
Address = model.Address,
|
||||||
OpeningDate = model.OpeningDate,
|
OpeningDate = model.OpeningDate,
|
||||||
|
MaxSecuresCount = model.MaxSecuresCount,
|
||||||
ShopSecures = new()
|
ShopSecures = new()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -39,6 +40,7 @@ namespace SecuritySystemListImplement.Models
|
|||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
Address = model.Address;
|
Address = model.Address;
|
||||||
OpeningDate = model.OpeningDate;
|
OpeningDate = model.OpeningDate;
|
||||||
|
MaxSecuresCount = model.MaxSecuresCount;
|
||||||
ShopSecures = model.ShopSecures;
|
ShopSecures = model.ShopSecures;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +50,7 @@ namespace SecuritySystemListImplement.Models
|
|||||||
Name = Name,
|
Name = Name,
|
||||||
Address = Address,
|
Address = Address,
|
||||||
OpeningDate = OpeningDate,
|
OpeningDate = OpeningDate,
|
||||||
|
MaxSecuresCount = MaxSecuresCount,
|
||||||
ShopSecures = ShopSecures
|
ShopSecures = ShopSecures
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user