|
|
@ -5,7 +5,9 @@ using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Model
|
|
|
|
namespace Model
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Define a Recipe for the preparation of a meal.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public class Recipe : IEquatable<Recipe>
|
|
|
|
public class Recipe : IEquatable<Recipe>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
#region Attributes
|
|
|
@ -15,7 +17,15 @@ namespace Model
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The ID of the recipe - allows you to compare and/or get this item in an easier way.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public int Id { get; init; }
|
|
|
|
public int Id { get; init; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The Title of the recipe. <br/>
|
|
|
|
|
|
|
|
/// Set to "No title." when the value passed is null, empty or contain white spaces.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public string? Title
|
|
|
|
public string? Title
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => _title;
|
|
|
|
get => _title;
|
|
|
@ -27,28 +37,26 @@ namespace Model
|
|
|
|
_title = value;
|
|
|
|
_title = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public string? Description
|
|
|
|
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
get => _description;
|
|
|
|
/// The steps of the preparation. See: <see cref="PreparationStep"/>.
|
|
|
|
set
|
|
|
|
/// </summary>
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
|
|
|
|
|
|
_description = "No description.";
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
_description = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<PreparationStep>? PreparationSteps { get; private set; }
|
|
|
|
public List<PreparationStep>? PreparationSteps { get; private set; }
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
#region Constructors
|
|
|
|
public Recipe(string? title = null, string? description = null, int? id = null,
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Construct a new recipe.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="title">The title of the recipe</param>
|
|
|
|
|
|
|
|
/// <param name="id">The id of the recipe. If not given, get a new id.</param>
|
|
|
|
|
|
|
|
/// <param name="preparationSteps">The steps of the preparation of the meal</param>
|
|
|
|
|
|
|
|
public Recipe(string? title = null, int? id = null,
|
|
|
|
params PreparationStep[] preparationSteps)
|
|
|
|
params PreparationStep[] preparationSteps)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (id == null) Id = idCreator++;
|
|
|
|
if (id == null) Id = idCreator++;
|
|
|
|
else Id = (int)id;
|
|
|
|
else Id = (int)id;
|
|
|
|
Title = title;
|
|
|
|
Title = title;
|
|
|
|
Description = description;
|
|
|
|
|
|
|
|
PreparationSteps = new List<PreparationStep>(preparationSteps);
|
|
|
|
PreparationSteps = new List<PreparationStep>(preparationSteps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
@ -58,7 +66,7 @@ namespace Model
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (other == null) return false;
|
|
|
|
if (other == null) return false;
|
|
|
|
if (other == this) return true;
|
|
|
|
if (other == this) return true;
|
|
|
|
return Title.Equals(other.Title) && Description.Equals(other.Description);
|
|
|
|
return Title.Equals(other.Title) && PreparationSteps.Equals(other.PreparationSteps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
public override int GetHashCode()
|
|
|
@ -68,7 +76,7 @@ namespace Model
|
|
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder($"[Recipe] - {Title}: {Description}\n");
|
|
|
|
StringBuilder sb = new StringBuilder($"[Recipe n°{Id}] - {Title}\n");
|
|
|
|
foreach (PreparationStep ps in PreparationSteps)
|
|
|
|
foreach (PreparationStep ps in PreparationSteps)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sb.AppendFormat("\t* {0}\n", ps.ToString());
|
|
|
|
sb.AppendFormat("\t* {0}\n", ps.ToString());
|
|
|
|