PIbd-22_Kaznacheeva.E.K._So.../SoftwareInstallation/SoftwareInstallationListImplement/Package.cs

56 lines
1.6 KiB
C#
Raw Normal View History

2024-02-27 23:44:38 +04:00
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationListImplement.Models
{
public class Package : IPackageModel
{
public int Id { get; private set; }
public string PackageName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> PackageComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Package? Create(PackageBindingModel? model)
{
if (model == null)
{
return null;
}
return new Package()
{
Id = model.Id,
PackageName = model.PackageName,
Price = model.Price,
PackageComponents = model.PackageComponents
};
}
public void Update(PackageBindingModel? model)
{
if (model == null)
{
return;
}
PackageName = model.PackageName;
Price = model.Price;
PackageComponents = model.PackageComponents;
}
public PackageViewModel GetViewModel => new()
{
Id = Id,
PackageName = PackageName,
Price = Price,
PackageComponents = PackageComponents
};
}
}