Исправление ошибок
This commit is contained in:
parent
baed74da66
commit
f9c2fb9701
@ -27,7 +27,10 @@ namespace AbstractSoftwareInstallationFileImplement.Implements
|
||||
return null;
|
||||
}
|
||||
return source.Packages
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PackageName) && x.PackageName == model.PackageName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.PackageName)
|
||||
&& x.PackageName == model.PackageName)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<PackageViewModel> GetFilteredList(PackageSearchModel model)
|
||||
|
@ -34,7 +34,9 @@ namespace AbstractSoftwareInstallationFileImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _source.Softwares.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SoftwareName) && x.SoftwareName == model.SoftwareName)
|
||||
return _source.Softwares.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.SoftwareName)
|
||||
&& x.SoftwareName == model.SoftwareName)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public SoftwareViewModel? Insert(SoftwareBindingModel model)
|
||||
|
@ -12,27 +12,33 @@ namespace AbstractSoftwareInstallationFileImplement.Models
|
||||
{
|
||||
internal class Package : IPackageModel
|
||||
{
|
||||
public string PackageName { get; private set; } = String.Empty;
|
||||
public int Id { get; private set; }
|
||||
public string PackageName { get; private set; } = string.Empty;
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Softwares { get; private set; } = new();
|
||||
private Dictionary<int, (ISoftwareModel, int)> _packageSoftware = null;
|
||||
|
||||
private Dictionary<int, (ISoftwareModel, int)>? _PackageSoftware = null;
|
||||
public Dictionary<int, (ISoftwareModel, int)> PackageSoftware
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_packageSoftware == null)
|
||||
if (_PackageSoftware == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_packageSoftware = Softwares.ToDictionary(
|
||||
_PackageSoftware = Softwares.ToDictionary(
|
||||
x => x.Key,
|
||||
y => ((source.Softwares.FirstOrDefault(z => z.Id == y.Key) as ISoftwareModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _packageSoftware;
|
||||
return _PackageSoftware;
|
||||
}
|
||||
}
|
||||
public static Package? Create(PackageBindingModel model)
|
||||
|
||||
|
||||
public static Package? Create(PackageBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -43,10 +49,10 @@ namespace AbstractSoftwareInstallationFileImplement.Models
|
||||
Id = model.Id,
|
||||
PackageName = model.PackageName,
|
||||
Price = model.Price,
|
||||
Softwares = model.PackageSoftware.ToDictionary(x => x.Key,
|
||||
x => x.Value.Item2)
|
||||
Softwares = model.PackageSoftware.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Package? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
@ -58,13 +64,14 @@ namespace AbstractSoftwareInstallationFileImplement.Models
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
PackageName = element.Element("PackageName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Softwares = element.Element("PackageSoftwares")!.Elements("PackageSoftware").ToDictionary(
|
||||
Softwares = element.Element("PackageSoftware")!.Elements("PackageSoftware").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||
)
|
||||
)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void Update(PackageBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -74,6 +81,7 @@ namespace AbstractSoftwareInstallationFileImplement.Models
|
||||
PackageName = model.PackageName;
|
||||
Price = model.Price;
|
||||
Softwares = model.PackageSoftware.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_PackageSoftware = null;
|
||||
}
|
||||
public PackageViewModel GetViewModel => new()
|
||||
{
|
||||
@ -82,11 +90,18 @@ namespace AbstractSoftwareInstallationFileImplement.Models
|
||||
Price = Price,
|
||||
PackageSoftware = PackageSoftware
|
||||
};
|
||||
public XElement GetXElement => new("Software",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PackageName", PackageName),
|
||||
new XElement("Price", Price.ToString()));
|
||||
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Package",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PackageName", PackageName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("PackageSoftware", Softwares.Select(x =>
|
||||
new XElement("PackageSoftware",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user