cm bf m user for data persistance correction

pull/44/head
Alexandre AGOSTINHO 2 years ago
parent 57a9b27d1c
commit e9a78a4874

@ -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;

@ -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

@ -25,6 +25,9 @@ namespace Model
[DataMember(Name = "id")]
public int Id { get; init; }
/// <summary>
/// List of reviews of this recipe.
/// </summary>
[DataMember(Name = "reviews")]
public List<Review> Reviews { get; private set; }
@ -94,12 +97,31 @@ namespace Model
: this(title, null, new List<Review>(), 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>
public Recipe(string title, int? id, params PreparationStep[] preparationSteps)
: this(title, id, new List<Review>(), preparationSteps)
{
}
#endregion
#region Methods
/// <summary>
/// Add a review for the recipe.
/// </summary>
/// <param name="review">The new review to add.</param>
public void AddReview(Review review)
=> Reviews.Add(review);
/// <summary>
/// Get a string representing all the reviews and their informations.
/// </summary>
/// <returns></returns>
public string GetReviews()
{
StringBuilder sb = new StringBuilder("Reviews:\n------------------------------\n");

@ -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<Review>
{
[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

Loading…
Cancel
Save