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.
60 lines
2.0 KiB
60 lines
2.0 KiB
using System.Text;
|
|
|
|
namespace Model
|
|
{
|
|
public class Recipe
|
|
{
|
|
public uint Id { get; set; }
|
|
public string Title { get; set; }
|
|
public List<string> Ingredients { get; set; }
|
|
public string Preparation { get; set; }
|
|
|
|
/// <summary>
|
|
/// Constructor of a Recipe.
|
|
/// </summary>
|
|
/// <param name="id">Identificator</param>
|
|
/// <param name="title">The name of the recipe</param>
|
|
/// <param name="ingredients">A list of ingredient needed by the preparation</param>
|
|
/// <param name="preparation">The text that explain the preparation of the recipe</param>
|
|
public Recipe(uint id, string title, List<string> ingredients, string preparation)
|
|
{
|
|
Id = id;
|
|
Title = title;
|
|
Ingredients = ingredients;
|
|
Preparation = preparation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Concatenate the list of ingredients in a single string
|
|
/// </summary>
|
|
/// <returns>The list of ingredients in string format</returns>
|
|
private string ConcatIngredients()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (string str in Ingredients) sb.Append("\t- " + str + "\n");
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Build a string with all elements (title, ingredients, preparation, ...)
|
|
/// </summary>
|
|
/// <returns>A string that represent the recipe</returns>
|
|
public override string ToString()
|
|
{
|
|
return $"{Title} -- id:{Id}\n\n"
|
|
+ "List of ingredient:\n"
|
|
+ ConcatIngredients() + "\n\n"
|
|
+ "Preparation:\n"
|
|
+ $"{Preparation}\n";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Display the recipe in the console
|
|
/// </summary>
|
|
public void Display()
|
|
{
|
|
Console.WriteLine(this.ToString());
|
|
}
|
|
}
|
|
} |