In progress
This commit is contained in:
parent
5533bb0f85
commit
d8025b18bd
@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopContracts", "Secu
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopListImplement", "SecureShopListImplement\SecureShopListImplement.csproj", "{1FECFDBF-32E0-4D94-B922-BE690F2408BC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopListImplement", "SecureShopListImplement\SecureShopListImplement.csproj", "{1FECFDBF-32E0-4D94-B922-BE690F2408BC}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopFileImplement", "SecureShopFileImplement\SecureShopFileImplement.csproj", "{3E416EAB-041A-46EE-9017-2C3D7127D802}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -39,6 +41,10 @@ Global
|
|||||||
{1FECFDBF-32E0-4D94-B922-BE690F2408BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{1FECFDBF-32E0-4D94-B922-BE690F2408BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{1FECFDBF-32E0-4D94-B922-BE690F2408BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{1FECFDBF-32E0-4D94-B922-BE690F2408BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{1FECFDBF-32E0-4D94-B922-BE690F2408BC}.Release|Any CPU.Build.0 = Release|Any CPU
|
{1FECFDBF-32E0-4D94-B922-BE690F2408BC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
<ProjectReference Include="..\SecureShopBusinessLogic\SecureShopBusinessLogic.csproj" />
|
<ProjectReference Include="..\SecureShopBusinessLogic\SecureShopBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\SecureShopContracts\SecureShopContracts.csproj" />
|
<ProjectReference Include="..\SecureShopContracts\SecureShopContracts.csproj" />
|
||||||
<ProjectReference Include="..\SecureShopListImplement\SecureShopListImplement.csproj" />
|
<ProjectReference Include="..\SecureShopListImplement\SecureShopListImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\SecureShopListImplement\SecureShopFileImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
50
Secure/SecureShopFileImplement/DataFileSingleton.cs
Normal file
50
Secure/SecureShopFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using SecureShopFileImplement.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace SecureShopFileImplement
|
||||||
|
{
|
||||||
|
public class DataFileSingleton
|
||||||
|
{
|
||||||
|
private static DataFileSingleton? instance;
|
||||||
|
private readonly string FacilitiesFileName = "Facilities.xml";
|
||||||
|
private readonly string OrderFileName = "Order.xml";
|
||||||
|
private readonly string SecureFileName = "Secure.xml";
|
||||||
|
public List<Facilities> Facilitiess { get; private set; }
|
||||||
|
public List<Order> Orders { get; private set; }
|
||||||
|
public List<Secure> Secures { get; private set; }
|
||||||
|
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new DataFileSingleton();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveFacilitiess() => SaveData(Facilitiess, FacilitiesFileName, "Facilitiess", x => x.GetXElement);
|
||||||
|
public void SaveSecures() => SaveData(Secures, SecureFileName, "Secures", x => x.GetXElement);
|
||||||
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
|
private DataFileSingleton()
|
||||||
|
{
|
||||||
|
Facilitiess = LoadData(FacilitiesFileName, "Facilities", x => Facilities.Create(x)!)!;
|
||||||
|
Secures = LoadData(SecureFileName, "Secure", x => Secure.Create(x)!)!;
|
||||||
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
}
|
||||||
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||||
|
}
|
||||||
|
return new List<T>();
|
||||||
|
}
|
||||||
|
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||||
|
{
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.SearchModels;
|
||||||
|
using SecureShopContracts.StoragesContracts;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace SecureShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class FacilitiesStorage : IFacilitiesStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton _source;
|
||||||
|
|
||||||
|
public FacilitiesStorage()
|
||||||
|
{
|
||||||
|
_source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FacilitiesViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return _source.Facilitiess.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FacilitiesViewModel> GetFilteredList(FacilitiesSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.FacilitiesName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return _source.Facilitiess.Where(x => x.FacilitiesName.Contains(model.FacilitiesName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel? GetElement(FacilitiesSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.FacilitiesName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _source.Facilitiess.FirstOrDefault(x => (!string.IsNullOrEmpty(model.FacilitiesName) && x.FacilitiesName == model.FacilitiesName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel? Insert(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = _source.Facilitiess.Count > 0 ? _source.Facilitiess.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newFacilities = Facilities.Create(model);
|
||||||
|
if (newFacilities == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Facilitiess.Add(newFacilities);
|
||||||
|
_source.SaveFacilitiess();
|
||||||
|
return newFacilities.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel? Update(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
var Facilities = _source.Facilitiess.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Facilities == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Facilities.Update(model);
|
||||||
|
_source.SaveFacilitiess();
|
||||||
|
return Facilities.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel? Delete(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
var element = _source.Facilitiess.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
_source.Facilitiess.Remove(element);
|
||||||
|
_source.SaveFacilitiess();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
90
Secure/SecureShopFileImplement/Implements/OrderStorage.cs
Normal file
90
Secure/SecureShopFileImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.SearchModels;
|
||||||
|
using SecureShopContracts.StoragesContracts;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace SecureShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton _source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
_source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return _source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return _source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
|
||||||
|
}
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderViewModel GetViewModel(Order order)
|
||||||
|
{
|
||||||
|
var viewModel = order.GetViewModel;
|
||||||
|
foreach (var Secure in _source.Secures)
|
||||||
|
{
|
||||||
|
if (Secure.Id == order.SecureId)
|
||||||
|
{
|
||||||
|
viewModel.SecureName = Secure.SecureName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return viewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Orders.Add(newOrder);
|
||||||
|
_source.SaveOrders();
|
||||||
|
return GetViewModel(newOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
_source.SaveOrders();
|
||||||
|
return GetViewModel(order);
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order != null)
|
||||||
|
{
|
||||||
|
_source.Orders.Remove(order);
|
||||||
|
_source.SaveOrders();
|
||||||
|
return GetViewModel(order);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
Secure/SecureShopFileImplement/Implements/SecureStorage.cs
Normal file
78
Secure/SecureShopFileImplement/Implements/SecureStorage.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.SearchModels;
|
||||||
|
using SecureShopContracts.StoragesContracts;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace SecureShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class SecureStorage : ISecureStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton _source;
|
||||||
|
|
||||||
|
public SecureStorage()
|
||||||
|
{
|
||||||
|
_source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SecureViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return _source.Secures.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SecureViewModel> GetFilteredList(SecureSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SecureName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return _source.Secures.Where(x => x.SecureName.Contains(model.SecureName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SecureViewModel? GetElement(SecureSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _source.Secures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SecureName) && x.SecureName == model.SecureName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SecureViewModel? Insert(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = _source.Secures.Count > 0 ? _source.Secures.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newSecure = Secure.Create(model);
|
||||||
|
if (newSecure == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Secures.Add(newSecure);
|
||||||
|
_source.SaveSecures();
|
||||||
|
return newSecure.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SecureViewModel? Update(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
var Secure = _source.Secures.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Secure == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Secure.Update(model);
|
||||||
|
_source.SaveSecures();
|
||||||
|
return Secure.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SecureViewModel? Delete(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
var element = _source.Secures.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
_source.Secures.Remove(element);
|
||||||
|
_source.SaveSecures();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
Secure/SecureShopFileImplement/Models/Facilities.cs
Normal file
61
Secure/SecureShopFileImplement/Models/Facilities.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace SecureShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Facilities : IFacilitiesModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string FacilitiesName { get; private set; } = string.Empty;
|
||||||
|
public double Cost { get; set; }
|
||||||
|
|
||||||
|
public static Facilities? Create(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Facilities()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FacilitiesName = model.FacilitiesName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Facilities? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Facilities()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
FacilitiesName = element.Element("FacilitiesName")!.Value,
|
||||||
|
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FacilitiesName = model.FacilitiesName;
|
||||||
|
Cost = model.Cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
FacilitiesName = FacilitiesName,
|
||||||
|
Cost = Cost
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Facilities",new XAttribute("Id", Id), new XElement("FacilitiesName", FacilitiesName), new XElement("Cost", Cost.ToString()));
|
||||||
|
}
|
||||||
|
}
|
87
Secure/SecureShopFileImplement/Models/Order.cs
Normal file
87
Secure/SecureShopFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDataModels.Enums;
|
||||||
|
using SecureShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace SecureShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int SecureId { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
|
public double Sum { get; private set; }
|
||||||
|
public OrderStatus Status { get; private set; }
|
||||||
|
public DateTime DateCreate { get; private set; }
|
||||||
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SecureId = model.SecureId,
|
||||||
|
Count = model.Count,
|
||||||
|
Sum = model.Sum,
|
||||||
|
Status = model.Status,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Order? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var order = new Order()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
SecureId = Convert.ToInt32(element.Element("SecureId")!.Value),
|
||||||
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
|
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||||
|
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
|
||||||
|
DateImplement = Convert.ToDateTime(element.Element("DateCreate")!.Value)
|
||||||
|
};
|
||||||
|
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
|
||||||
|
order.DateImplement = dateImpl;
|
||||||
|
|
||||||
|
if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Status = status;
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
SecureId = SecureId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("SecureId", SecureId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), new XElement("DateImplement", DateImplement.ToString())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
79
Secure/SecureShopFileImplement/Models/Secure.cs
Normal file
79
Secure/SecureShopFileImplement/Models/Secure.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace SecureShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Secure : ISecureModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string SecureName { get; private set; } = string.Empty;
|
||||||
|
public double Price { get; private set; }
|
||||||
|
public Dictionary<int, int> Facilitiess { get; private set; } = new();
|
||||||
|
private Dictionary<int, (IFacilitiesModel, int)>? _SecureFacilitiess = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (IFacilitiesModel, int)> SecureFacilitiess
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_SecureFacilitiess == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_SecureFacilitiess = Facilitiess.ToDictionary(x => x.Key, y => ((source.Facilitiess.FirstOrDefault(z => z.Id == y.Key) as IFacilitiesModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _SecureFacilitiess;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Secure? Create(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Secure()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SecureName = model.SecureName,
|
||||||
|
Price = model.Price,
|
||||||
|
Facilitiess = model.SecureFacilitiess.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Secure? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Secure()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
SecureName = element.Element("SecureName")!.Value,
|
||||||
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||||
|
Facilitiess = element.Element("SecureFacilitiess")!.Elements("SecureFacilities").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SecureName = model.SecureName;
|
||||||
|
Price = model.Price;
|
||||||
|
Facilitiess = model.SecureFacilitiess.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_SecureFacilitiess = null;
|
||||||
|
}
|
||||||
|
public SecureViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
SecureName = SecureName,
|
||||||
|
Price = Price,
|
||||||
|
SecureFacilitiess = SecureFacilitiess
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Secure", new XAttribute("Id", Id), new XElement("SecureName", SecureName), new XElement("Price", Price.ToString()), new XElement("SecureFacilitiess", Facilitiess.Select(x => new XElement("SecureFacilities", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SecureShopContracts\SecureShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\SecureShopDataModels\SecureShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user