PIbd-23-Volkov-N.A.-Compute.../ComputersShop/ComputersShopListImplement/Models/Computer.cs

55 lines
1.6 KiB
C#
Raw Normal View History

2024-02-05 20:36:39 +04:00
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.ViewModels;
using ComputersShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopListImplement.Models
{
public class Computer : IComputerModel
{
public int Id { get; private set; }
public string ComputerName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> ComputerComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Computer? Create(ComputerBindingModel? model)
{
if (model == null)
{
return null;
}
return new Computer()
{
Id = model.Id,
ComputerName = model.ComputerName,
Price = model.Price,
ComputerComponents = model.ComputerComponents
};
}
public void Update(ComputerBindingModel? model)
{
if (model == null)
{
return;
}
ComputerName = model.ComputerName;
Price = model.Price;
ComputerComponents = model.ComputerComponents;
}
public ComputerViewModel GetViewModel => new()
{
Id = Id,
ComputerName = ComputerName,
Price = Price,
ComputerComponents = ComputerComponents
};
}
}