PIbd-23-Nasyrov-A.G.-Flower.../FlowerShopListImplement/Flower.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2024-02-08 16:12:43 +04:00
using FlowerShopDataModels.Models;
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FlowerShopListImplement.Models
{
public class Flower : IFlowerModel
{
public int Id { get; private set; }
public string FlowerName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> FlowerComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Flower? Create(FlowerBindingModel? model)
{
if (model == null)
{
return null;
}
return new Flower()
{
Id = model.Id,
FlowerName = model.FlowerName,
Price = model.Price,
FlowerComponents = model.FlowerComponents
};
}
public void Update(FlowerBindingModel? model)
{
if (model == null)
{
return;
}
FlowerName = model.FlowerName;
Price = model.Price;
FlowerName = model.FlowerName;
}
public FlowerViewModel GetViewModel => new()
{
Id = Id,
FlowerName = FlowerName,
Price = Price,
FlowerComponents = FlowerComponents
};
}
}