|
|
|
@ -31,6 +31,12 @@ namespace Model
|
|
|
|
|
[DataMember(Name = "reviews")]
|
|
|
|
|
public List<Review> Reviews { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Author of the recipe.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataMember(Name = "author")]
|
|
|
|
|
public User? Author { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Title of the recipe. <br/>
|
|
|
|
|
/// Set to "No title." when the value passed is null, empty or contain white spaces.
|
|
|
|
@ -47,6 +53,12 @@ namespace Model
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The list of ingredients.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataMember(Name = "ingredient")]
|
|
|
|
|
public List<Ingredient> Ingredients { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The steps of the preparation. See: <see cref="PreparationStep"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -58,16 +70,20 @@ namespace Model
|
|
|
|
|
/// <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,
|
|
|
|
|
List<Review> reviews,
|
|
|
|
|
/// <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="reviews">Thr list of reviews.</param>
|
|
|
|
|
/// <param _name="ingredients">Thr list of ingredients.</param>
|
|
|
|
|
/// <param _name="preparationSteps">The steps of the preparation of the meal</param>
|
|
|
|
|
public Recipe(string title, int? id, User? author,
|
|
|
|
|
List<Review> reviews, List<Ingredient> ingredients,
|
|
|
|
|
params PreparationStep[] preparationSteps)
|
|
|
|
|
{
|
|
|
|
|
Title = title;
|
|
|
|
|
PreparationSteps = new List<PreparationStep>(preparationSteps);
|
|
|
|
|
Ingredients = ingredients;
|
|
|
|
|
Reviews = reviews;
|
|
|
|
|
Author = author;
|
|
|
|
|
|
|
|
|
|
if (id == null)
|
|
|
|
|
{
|
|
|
|
@ -82,30 +98,43 @@ namespace Model
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="title">The title of the recipe.</param>
|
|
|
|
|
/// <param _name="title">The title of the recipe.</param>
|
|
|
|
|
public Recipe(string title)
|
|
|
|
|
: this(title, null, new List<Review>())
|
|
|
|
|
: this(title, null, null, new List<Review>(), new List<Ingredient>())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="title">The title of the recipe.</param>
|
|
|
|
|
/// <param name="preparationSteps">The steps of the preparation of the meal.</param>
|
|
|
|
|
/// <param _name="title">The title of the recipe.</param>
|
|
|
|
|
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
|
|
|
|
|
public Recipe(string title, params PreparationStep[] preparationSteps)
|
|
|
|
|
: this(title, null, new List<Review>(), preparationSteps)
|
|
|
|
|
: this(title, null, null, new List<Review>(), new List<Ingredient>(), preparationSteps)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
|
|
|
|
|
/// </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>
|
|
|
|
|
/// <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, params PreparationStep[] preparationSteps)
|
|
|
|
|
: this(title, id, new List<Review>(), preparationSteps)
|
|
|
|
|
: this(title, id, null, new List<Review>(), new List<Ingredient>(), preparationSteps)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
|
|
|
|
|
/// </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="ingredients">Thr list of ingredients.</param>
|
|
|
|
|
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
|
|
|
|
|
public Recipe(string title, int? id, List<Ingredient> ingredients,
|
|
|
|
|
params PreparationStep[] preparationSteps)
|
|
|
|
|
: this(title, id, null, new List<Review>(), ingredients, preparationSteps)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
@ -114,7 +143,7 @@ namespace Model
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add a review for the recipe.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="review">The new review to add.</param>
|
|
|
|
|
/// <param _name="review">The new review to add.</param>
|
|
|
|
|
public void AddReview(Review review)
|
|
|
|
|
=> Reviews.Add(review);
|
|
|
|
|
|
|
|
|
@ -132,6 +161,22 @@ namespace Model
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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 (Ingredient ingredient in Ingredients)
|
|
|
|
|
{
|
|
|
|
|
sb.Append("\t- " + ingredient.ToString() + "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool Equals(Recipe? other)
|
|
|
|
|
{
|
|
|
|
|
if (other == null) return false;
|
|
|
|
@ -159,10 +204,14 @@ namespace Model
|
|
|
|
|
sb.AppendFormat("\t* {0}\n", ps.ToString());
|
|
|
|
|
}
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
sb.AppendLine(ConcatIngredients());
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
foreach (Review review in Reviews)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine(review.ToString());
|
|
|
|
|
}
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
sb.AppendLine($"Posted by: {Author?.ToString()}");
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|