diff --git a/MCTG/DataPersistence/DataContractJSON.cs b/MCTG/DataPersistence/DataContractJSON.cs
index 382a4eb..05db57e 100644
--- a/MCTG/DataPersistence/DataContractJSON.cs
+++ b/MCTG/DataPersistence/DataContractJSON.cs
@@ -34,7 +34,12 @@ namespace DataPersistence
if (dataContractJsonSerializerSettings is null)
_dataContractJsonSerializerSettings = new DataContractJsonSerializerSettings()
{
- KnownTypes = new[] { typeof(Recipe) }
+ KnownTypes = new[]
+ {
+ typeof(Recipe),
+ typeof(Review),
+ typeof(User)
+ }
};
else
_dataContractJsonSerializerSettings = dataContractJsonSerializerSettings;
diff --git a/MCTG/DataPersistence/DataContractXML.cs b/MCTG/DataPersistence/DataContractXML.cs
index 3944c85..92f4baf 100644
--- a/MCTG/DataPersistence/DataContractXML.cs
+++ b/MCTG/DataPersistence/DataContractXML.cs
@@ -42,7 +42,12 @@ namespace DataPersistence
if (dataContractSerializerSettings is null)
_dataContractSerializerSettings = new DataContractSerializerSettings()
{
- KnownTypes = new Type[] { typeof(Recipe) },
+ KnownTypes = new Type[]
+ {
+ typeof(Recipe),
+ typeof(Review),
+ typeof(User)
+ },
PreserveObjectReferences = true
};
else
diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs
index de29cfc..b7ced0d 100644
--- a/MCTG/Model/Recipes/Recipe.cs
+++ b/MCTG/Model/Recipes/Recipe.cs
@@ -25,6 +25,9 @@ namespace Model
[DataMember(Name = "id")]
public int Id { get; init; }
+ ///
+ /// List of reviews of this recipe.
+ ///
[DataMember(Name = "reviews")]
public List Reviews { get; private set; }
@@ -94,12 +97,31 @@ namespace Model
: this(title, null, new List(), preparationSteps)
{
}
+
+ ///
+ ///
+ ///
+ /// The title of the recipe.
+ /// The id of the recipe. If not given, get a new id.
+ /// The steps of the preparation of the meal.
+ public Recipe(string title, int? id, params PreparationStep[] preparationSteps)
+ : this(title, id, new List(), preparationSteps)
+ {
+ }
#endregion
#region Methods
+ ///
+ /// Add a review for the recipe.
+ ///
+ /// The new review to add.
public void AddReview(Review review)
=> Reviews.Add(review);
+ ///
+ /// Get a string representing all the reviews and their informations.
+ ///
+ ///
public string GetReviews()
{
StringBuilder sb = new StringBuilder("Reviews:\n------------------------------\n");
diff --git a/MCTG/Model/Recipes/Review.cs b/MCTG/Model/Recipes/Review.cs
index bd0a988..caf19cc 100644
--- a/MCTG/Model/Recipes/Review.cs
+++ b/MCTG/Model/Recipes/Review.cs
@@ -1,19 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
+using System.Xml.Linq;
namespace Model
{
+ [DataContract(Name = "review")]
public class Review : IEquatable
{
+ [DataMember(Name = "stars")]
private int _stars;
+
+ [DataMember(Name = "content")]
private string _content = "";
+ [DataMember(Name = "id")]
public int Id { get; init; }
+ [DataMember(Name = "author")]
public User Author { get; private set; }
public int Stars