55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
|
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
|
|||
|
};
|
|||
|
}
|
|||
|
}
|