You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.8 KiB
73 lines
1.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Model
|
|
{
|
|
[DataContract(Name = "ingredient")]
|
|
public class Ingredient
|
|
{
|
|
#region Attributes
|
|
[DataMember(Name = "id")]
|
|
private string _name = "";
|
|
|
|
[DataMember(Name = "quantity")]
|
|
private Quantity _quantity = new Quantity(1, Unit.unit);
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
/// <summary>
|
|
/// Property of the Ingredient's attribute _name. It raises an ArgumentNullException to prevent a nullable field.
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get => _name;
|
|
set
|
|
{
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient");
|
|
}
|
|
_name = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Property of the Ingredient's attribute Quantity.
|
|
/// </summary>
|
|
public Quantity QuantityI
|
|
{
|
|
get => _quantity;
|
|
set => _quantity = value;
|
|
|
|
}
|
|
|
|
|
|
public bool Equals(Ingredient? other)
|
|
{
|
|
if (other == null) { return false; }
|
|
if (this == other) { return true; }
|
|
return Name.Equals(other.Name);
|
|
}
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public Ingredient(string name, Quantity quantity)
|
|
{
|
|
Name = name;
|
|
QuantityI = quantity;
|
|
}
|
|
#endregion
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{Name} ({QuantityI})";
|
|
}
|
|
}
|
|
}
|