fix ingredient

pull/47/head
Alexandre AGOSTINHO 2 years ago
parent 91573ffdea
commit 86f6f73cea

@ -11,8 +11,8 @@ Console.WriteLine("Hello, World!\n\n");
// TESTS: // TESTS:
//DataManager dataMgr = new DataManager(new Stubs()); DataManager dataMgr = new DataManager(new Stubs());
DataManager dataMgr = new DataManager(new DataContractXML()); //DataManager dataMgr = new DataManager(new DataContractXML());
//DataManager dataMgr = new DataManager(new DataContractJSON()); //DataManager dataMgr = new DataManager(new DataContractJSON());
dataMgr.Serializer = new DataContractXML(); dataMgr.Serializer = new DataContractXML();

@ -40,8 +40,7 @@ namespace DataPersistence
typeof(Review), typeof(Review),
typeof(User), typeof(User),
typeof(Ingredient), typeof(Ingredient),
typeof(Quantity), typeof(Quantity)
typeof(Unit)
} }
}; };
else else

@ -48,8 +48,7 @@ namespace DataPersistence
typeof(Review), typeof(Review),
typeof(User), typeof(User),
typeof(Ingredient), typeof(Ingredient),
typeof(Quantity), typeof(Quantity)
typeof(Unit)
}, },
PreserveObjectReferences = true PreserveObjectReferences = true
}; };

@ -12,26 +12,27 @@ namespace Model
{ {
#region Attributes #region Attributes
[DataMember(Name = "id")] [DataMember(Name = "id")]
private string name = ""; private string _name = "";
[DataMember(Name = "quantity")] [DataMember(Name = "quantity")]
private Quantity quantity = new Quantity(1, Unit.unit); private Quantity _quantity = new Quantity(1, Unit.unit);
#endregion #endregion
#region Properties #region Properties
/// <summary> /// <summary>
/// Property of the Ingredient's attribute name. It raises an ArgumentNullException to prevent a nullable field. /// Property of the Ingredient's attribute _name. It raises an ArgumentNullException to prevent a nullable field.
/// </summary> /// </summary>
public string Name public string Name
{ {
get => name; get => _name;
set set
{ {
if (value == null) if (string.IsNullOrEmpty(value))
{ {
throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient"); throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient");
} }
_name = value;
} }
} }
@ -40,8 +41,8 @@ namespace Model
/// </summary> /// </summary>
public Quantity QuantityI public Quantity QuantityI
{ {
get => quantity; get => _quantity;
set => quantity = value; set => _quantity = value;
} }

@ -8,8 +8,8 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
/// <summary> /// <summary>
/// Quantity is a class which is associate to Ingedients. It represents the quantity of every ingredient with an enum /// Quantity is a class which is associate to Ingedients. It represents the _quantity of every ingredient with an enum
/// to indicate the unit of the quantity. /// to indicate the unit of the _quantity.
/// </summary> /// </summary>
[DataContract(Name = "quantity")] [DataContract(Name = "quantity")]
public class Quantity public class Quantity
@ -21,7 +21,7 @@ namespace Model
[DataMember(Name = "digit")] [DataMember(Name = "digit")]
private int number; private int number;
/// <summary> /// <summary>
/// have the Unit enum of the quantity of ingredient /// have the Unit enum of the _quantity of ingredient
/// </summary> /// </summary>
[DataMember(Name = "unit")] [DataMember(Name = "unit")]
private Unit unit; private Unit unit;
@ -30,7 +30,7 @@ namespace Model
#region Properties #region Properties
/// <summary> /// <summary>
/// Represents the quantity in digits. The null value raise an argumentException. /// Represents the _quantity in digits. The null value raise an argumentException.
/// </summary> /// </summary>
public int Number public int Number
{ {
@ -56,8 +56,8 @@ namespace Model
/// <summary> /// <summary>
/// Constructor of Quantity /// Constructor of Quantity
/// </summary> /// </summary>
/// <param name="number"></param> /// <param _name="number"></param>
/// <param name="unit"></param> /// <param _name="unit"></param>
public Quantity(int number, Unit unit) public Quantity(int number, Unit unit)
{ {
Number = number; Number = number;

@ -11,7 +11,6 @@ namespace Model
/// Unit is an Enum that represents the units of quantities /// Unit is an Enum that represents the units of quantities
/// <list type="Unit, kG, mG, G, L, cL, mL"/> /// <list type="Unit, kG, mG, G, L, cL, mL"/>
/// </summary> /// </summary>
[DataContract(Name = "enumUnit")]
public enum Unit public enum Unit
{ unit, kG, mG, G, L, cL, mL }; { unit, kG, mG, G, L, cL, mL };
} }

@ -46,8 +46,8 @@ namespace Model
/// <summary> /// <summary>
/// Construct a new step of preparation. /// Construct a new step of preparation.
/// </summary> /// </summary>
/// <param name="order">The number of the order in preparation</param> /// <param _name="order">The number of the order in preparation</param>
/// <param name="description">The description of the task</param> /// <param _name="description">The description of the task</param>
public PreparationStep(int order, string description = "") public PreparationStep(int order, string description = "")
{ {
Order = order; Order = order;

@ -50,6 +50,7 @@ namespace Model
/// <summary> /// <summary>
/// The list of ingredients. /// The list of ingredients.
/// </summary> /// </summary>
[DataMember(Name = "ingredient")]
public List<Ingredient> Ingredients { get; set; } public List<Ingredient> Ingredients { get; set; }
/// <summary> /// <summary>
@ -63,11 +64,11 @@ namespace Model
/// <summary> /// <summary>
/// Construct a new recipe. /// Construct a new recipe.
/// </summary> /// </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="id">The id of the recipe. If not given, get a new id.</param>
/// <param name="reviews">Thr list of reviews.</param> /// <param _name="reviews">Thr list of reviews.</param>
/// <param name="ingredients">Thr list of ingredients.</param> /// <param _name="ingredients">Thr list of ingredients.</param>
/// <param name="preparationSteps">The steps of the preparation of the meal</param> /// <param _name="preparationSteps">The steps of the preparation of the meal</param>
public Recipe(string title, int? id, public Recipe(string title, int? id,
List<Review> reviews, List<Ingredient> ingredients, List<Review> reviews, List<Ingredient> ingredients,
params PreparationStep[] preparationSteps) params PreparationStep[] preparationSteps)
@ -90,7 +91,7 @@ namespace Model
/// <summary> /// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> /// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> /// </summary>
/// <param name="title">The title of the recipe.</param> /// <param _name="title">The title of the recipe.</param>
public Recipe(string title) public Recipe(string title)
: this(title, null, new List<Review>(), new List<Ingredient>()) : this(title, null, new List<Review>(), new List<Ingredient>())
{ {
@ -99,8 +100,8 @@ namespace Model
/// <summary> /// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> /// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> /// </summary>
/// <param name="title">The title of the recipe.</param> /// <param _name="title">The title of the recipe.</param>
/// <param name="preparationSteps">The steps of the preparation of the meal.</param> /// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, params PreparationStep[] preparationSteps) public Recipe(string title, params PreparationStep[] preparationSteps)
: this(title, null, new List<Review>(), new List<Ingredient>(), preparationSteps) : this(title, null, new List<Review>(), new List<Ingredient>(), preparationSteps)
{ {
@ -109,9 +110,9 @@ namespace Model
/// <summary> /// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> /// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> /// </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="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="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, params PreparationStep[] preparationSteps) public Recipe(string title, int? id, params PreparationStep[] preparationSteps)
: this(title, id, new List<Review>(), new List<Ingredient>(), preparationSteps) : this(title, id, new List<Review>(), new List<Ingredient>(), preparationSteps)
{ {
@ -120,10 +121,10 @@ namespace Model
/// <summary> /// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> /// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> /// </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="id">The id of the recipe. If not given, get a new id.</param>
/// <param name="ingredients">Thr list of ingredients.</param> /// <param _name="ingredients">Thr list of ingredients.</param>
/// <param name="preparationSteps">The steps of the preparation of the meal.</param> /// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, List<Ingredient> ingredients, public Recipe(string title, int? id, List<Ingredient> ingredients,
params PreparationStep[] preparationSteps) params PreparationStep[] preparationSteps)
: this(title, id, new List<Review>(), ingredients, preparationSteps) : this(title, id, new List<Review>(), ingredients, preparationSteps)
@ -135,7 +136,7 @@ namespace Model
/// <summary> /// <summary>
/// Add a review for the recipe. /// Add a review for the recipe.
/// </summary> /// </summary>
/// <param name="review">The new review to add.</param> /// <param _name="review">The new review to add.</param>
public void AddReview(Review review) public void AddReview(Review review)
=> Reviews.Add(review); => Reviews.Add(review);
@ -162,7 +163,7 @@ namespace Model
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach (Ingredient ingredient in Ingredients) foreach (Ingredient ingredient in Ingredients)
{ {
sb.Append("\t- " + ingredient + "\n"); sb.Append("\t- " + ingredient.ToString() + "\n");
} }
return sb.ToString(); return sb.ToString();

@ -38,8 +38,8 @@ namespace Model
/// <summary> /// <summary>
/// Construct a new collection of _recipes. /// Construct a new collection of _recipes.
/// </summary> /// </summary>
/// <param name="description">A short description of what this list will contain</param> /// <param _name="description">A short description of what this list will contain</param>
/// <param name="recipes">Recipes to add in this new collection</param> /// <param _name="recipes">Recipes to add in this new collection</param>
public RecipeCollection(string description, params Recipe[] recipes) public RecipeCollection(string description, params Recipe[] recipes)
: base(recipes) : base(recipes)
{ {
@ -51,7 +51,7 @@ namespace Model
/// <summary> /// <summary>
/// Find a recipe in this list by giving the id. /// Find a recipe in this list by giving the id.
/// </summary> /// </summary>
/// <param name="id">The id of the list we are looking for</param> /// <param _name="id">The id of the list we are looking for</param>
/// <returns>The recipe of the id given</returns> /// <returns>The recipe of the id given</returns>
/// <exception cref="ArgumentException"/> /// <exception cref="ArgumentException"/>
public Recipe? GetRecipeById(int id) public Recipe? GetRecipeById(int id)
@ -62,9 +62,9 @@ namespace Model
} }
/// <summary> /// <summary>
/// Utility to find a recipe by his name. /// Utility to find a recipe by his _name.
/// </summary> /// </summary>
/// <param name="str">The string for the search</param> /// <param _name="str">The string for the search</param>
/// <returns>A collection of Recipe where their Title contain the string.</returns> /// <returns>A collection of Recipe where their Title contain the string.</returns>
public RecipeCollection ResearchByName(string str) public RecipeCollection ResearchByName(string str)
{ {

@ -11,7 +11,7 @@ using System.Runtime.Serialization;
namespace Model namespace Model
{ {
/// <summary> /// <summary>
/// A user is an entity with a name, a surname, mail, profilePict and a list of priority. /// A user is an entity with a _name, a surname, mail, profilePict and a list of priority.
/// This user can login with an Id and a password /// This user can login with an Id and a password
/// </summary> /// </summary>
[DataContract(Name = "user")] [DataContract(Name = "user")]
@ -137,9 +137,9 @@ namespace Model
/// <summary> /// <summary>
/// Construtors of user. /// Construtors of user.
/// </summary> /// </summary>
/// <param name="name">The name of the user</param> /// <param _name="name">The _name of the user</param>
/// <param name="surname">The surname of the user</param> /// <param _name="surname">The surname of the user</param>
/// <param name="mail">The user needs an email to login. </param> /// <param _name="mail">The user needs an email to login. </param>
public User(string name, string surname, string mail, int password) public User(string name, string surname, string mail, int password)
{ {
Name = name; Name = name;

Loading…
Cancel
Save