PIbd-21_Potapov_N.S._Securi.../SecuritySystem/SecuritySystemListImplement/Models/Secure.cs

51 lines
1.4 KiB
C#
Raw Normal View History

using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
namespace SecuritySystemListImplement.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, (IComponentModel, int)> SecureComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Secure? Create(SecureBindingModel? model)
{
if (model == null)
{
return null;
}
return new Secure()
{
Id = model.Id,
SecureName = model.SecureName,
Price = model.Price,
SecureComponents = model.SecureComponents
};
}
public void Update(SecureBindingModel? model)
{
if (model == null)
{
return;
}
SecureName = model.SecureName;
Price = model.Price;
SecureComponents = model.SecureComponents;
}
public SecureViewModel GetViewModel => new()
{
Id = Id,
SecureName = SecureName,
Price = Price,
SecureComponents = SecureComponents
};
}
}