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.
88 lines
2.6 KiB
88 lines
2.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
|
|
namespace Model
|
|
{
|
|
/// <summary>
|
|
/// Define a Recipe for the preparation of a meal.
|
|
/// </summary>
|
|
public class Recipe : IEquatable<Recipe>
|
|
{
|
|
#region Attributes
|
|
private string _title = "";
|
|
#endregion
|
|
|
|
#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; }
|
|
|
|
/// <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
|
|
{
|
|
get => _title;
|
|
set
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
_title = "No title.";
|
|
else
|
|
_title = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The steps of the preparation. See: <see cref="PreparationStep"/>.
|
|
/// </summary>
|
|
public List<PreparationStep> PreparationSteps { get; set; }
|
|
#endregion
|
|
|
|
#region Constructors
|
|
/// <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 = "", int? id = null,
|
|
params PreparationStep[] preparationSteps)
|
|
{
|
|
Title = title;
|
|
PreparationSteps = new List<PreparationStep>(preparationSteps);
|
|
|
|
if (id == null) Id = new Random().Next();
|
|
else Id = (int)id;
|
|
}
|
|
#endregion
|
|
|
|
#region Methods
|
|
public virtual bool Equals(Recipe? other)
|
|
{
|
|
if (other == null) return false;
|
|
if (other == this) return true;
|
|
return Title.Equals(other.Title) && PreparationSteps.Equals(other.PreparationSteps);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return Id.GetHashCode();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder($"[Recipe n°{Id}] - {Title}\n");
|
|
foreach (PreparationStep ps in PreparationSteps)
|
|
{
|
|
sb.AppendFormat("\t* {0}\n", ps.ToString());
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|