56 lines
1.6 KiB
C#
Raw Normal View History

2023-03-07 12:56:54 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
namespace SecuritySystemListImplement.Models
{
2023-03-07 12:47:29 +04:00
public class Secure : ISecureModel
2023-03-07 12:56:54 +04:00
{
public int Id { get; private set; }
2023-03-07 12:47:29 +04:00
public string SecureName { get; private set; } = string.Empty;
2023-03-07 12:56:54 +04:00
public double Price { get; private set; }
2023-03-07 12:47:29 +04:00
public Dictionary<int, (IComponentModel, int)> SecureComponents
2023-03-07 12:56:54 +04:00
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
2023-03-07 12:47:29 +04:00
public static Secure? Create(SecureBindingModel? model)
2023-03-07 12:56:54 +04:00
{
if (model == null)
{
return null;
}
return new Secure()
{
Id = model.Id,
2023-03-07 12:47:29 +04:00
SecureName = model.SecureName,
2023-03-07 12:56:54 +04:00
Price = model.Price,
2023-03-07 12:47:29 +04:00
SecureComponents = model.SecureComponents
2023-03-07 12:56:54 +04:00
};
}
2023-03-07 12:47:29 +04:00
public void Update(SecureBindingModel? model)
2023-03-07 12:56:54 +04:00
{
if (model == null)
{
return;
}
2023-03-07 12:47:29 +04:00
SecureName = model.SecureName;
2023-03-07 12:56:54 +04:00
Price = model.Price;
2023-03-07 12:47:29 +04:00
SecureComponents = model.SecureComponents;
2023-03-07 12:56:54 +04:00
}
2023-03-07 12:47:29 +04:00
public SecureViewModel GetViewModel => new()
2023-03-07 12:56:54 +04:00
{
Id = Id,
2023-03-07 12:47:29 +04:00
SecureName = SecureName,
2023-03-07 12:56:54 +04:00
Price = Price,
2023-03-07 12:47:29 +04:00
SecureComponents = SecureComponents
2023-03-07 12:56:54 +04:00
};
}
}