|
|
|
@ -13,6 +13,8 @@ namespace Model
|
|
|
|
|
{
|
|
|
|
|
#region Attributes
|
|
|
|
|
private string _title = "";
|
|
|
|
|
|
|
|
|
|
//private List<Review> _reviews;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
@ -21,6 +23,8 @@ namespace Model
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Id { get; init; }
|
|
|
|
|
|
|
|
|
|
public List<Review> Reviews { 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,15 +51,17 @@ namespace Model
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new recipe.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="title">The title of the recipe</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 = null,
|
|
|
|
|
params PreparationStep[] preparationSteps)
|
|
|
|
|
{
|
|
|
|
|
/// <param name="preparationSteps">The steps of the preparation of the meal.</param>
|
|
|
|
|
public Recipe(string title, int? id,
|
|
|
|
|
List<Review> reviews,
|
|
|
|
|
params PreparationStep[] preparationSteps)
|
|
|
|
|
{
|
|
|
|
|
Title = title;
|
|
|
|
|
PreparationSteps = new List<PreparationStep>(preparationSteps);
|
|
|
|
|
|
|
|
|
|
PreparationSteps = new List<PreparationStep>(preparationSteps);
|
|
|
|
|
Reviews = reviews;
|
|
|
|
|
|
|
|
|
|
if (id == null)
|
|
|
|
|
{
|
|
|
|
|
var randomGenerator = RandomNumberGenerator.Create();
|
|
|
|
@ -63,11 +69,44 @@ namespace Model
|
|
|
|
|
randomGenerator.GetBytes(data);
|
|
|
|
|
Id = Math.Abs(BitConverter.ToInt16(data));
|
|
|
|
|
}
|
|
|
|
|
else Id = (int)id;
|
|
|
|
|
else Id = (int)id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="title">The title of the recipe.</param>
|
|
|
|
|
public Recipe(string title)
|
|
|
|
|
: this(title, null, new List<Review>())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
public Recipe(string title, params PreparationStep[] preparationSteps)
|
|
|
|
|
: this(title, null, new List<Review>(), preparationSteps)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
|
|
public void AddReview(Review review)
|
|
|
|
|
=> Reviews.Add(review);
|
|
|
|
|
|
|
|
|
|
public string GetReviews()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder("Reviews:\n------------------------------\n");
|
|
|
|
|
foreach (Review review in Reviews)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine(review.ToString());
|
|
|
|
|
}
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool Equals(Recipe? other)
|
|
|
|
|
{
|
|
|
|
|
if (other == null) return false;
|
|
|
|
|