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 /// /// Property of the Ingredient's attribute _name. It raises an ArgumentNullException to prevent a nullable field. /// 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; } } /// /// Property of the Ingredient's attribute Quantity. /// 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})"; } } }