52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using SnackBarContracts.BindingModels;
|
|||
|
using SnackBarContracts.ViewModels;
|
|||
|
using SnackBarDataModels.Models;
|
|||
|
|
|||
|
|
|||
|
namespace SnackBarListImplement.Models
|
|||
|
{
|
|||
|
public class Snack : ISnackModel
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
public string SnackName { get; private set; } = string.Empty;
|
|||
|
public double Price { get; private set; }
|
|||
|
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
|
|||
|
public static Snack? Create(SnackBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Snack()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
SnackName = model.SnackName,
|
|||
|
Price = model.Price,
|
|||
|
SnackComponents = model.SnackComponents
|
|||
|
};
|
|||
|
}
|
|||
|
public void Update(SnackBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
SnackName = model.SnackName;
|
|||
|
Price = model.Price;
|
|||
|
SnackComponents = model.SnackComponents;
|
|||
|
}
|
|||
|
public SnackViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
SnackName = SnackName,
|
|||
|
Price = Price,
|
|||
|
SnackComponents = SnackComponents
|
|||
|
};
|
|||
|
}
|
|||
|
}
|