From 58902cea371df0ef1fdc3160b1b673f5e35c039a Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Tue, 16 May 2023 14:29:40 +0200 Subject: [PATCH 1/8] start comments --- MCTG/Model/Recipes/Review.cs | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 MCTG/Model/Recipes/Review.cs diff --git a/MCTG/Model/Recipes/Review.cs b/MCTG/Model/Recipes/Review.cs new file mode 100644 index 0000000..2c005e5 --- /dev/null +++ b/MCTG/Model/Recipes/Review.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + internal class Review + { + private int _stars; + private string _content = ""; + + public int Id { get; init; } + + public int Stars + { + get => _stars; + set + { + if (value < 0 || value > 5) throw new ArgumentException(nameof(Stars)); + else _stars = value; + } + } + + public string Content + { + get => _content; + set + { + if (string.IsNullOrEmpty(value)) _content = "No data..."; + else _content = value; + } + } + + public Review(int? id, int stars, string content) + { + if (id == null) + { + var randomGenerator = RandomNumberGenerator.Create(); + byte[] data = new byte[16]; + randomGenerator.GetBytes(data); + Id = Math.Abs(BitConverter.ToInt16(data)); + } + else Id = (int)id; + + Stars = stars; + Content = content; + } + + public Review(int stars, string content) : this(null, stars, content) + { + } + } +} From 1049c8f6d9c3b40a3d3624803b95ef2ef9c94014 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Tue, 16 May 2023 15:04:22 +0200 Subject: [PATCH 2/8] impl in recipe and add author --- MCTG/Model/Recipes/Recipe.cs | 55 ++++++++++++++++++++++++++++++------ MCTG/Model/Recipes/Review.cs | 34 ++++++++++++++++++++-- 2 files changed, 78 insertions(+), 11 deletions(-) diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs index 6048fdf..f63760e 100644 --- a/MCTG/Model/Recipes/Recipe.cs +++ b/MCTG/Model/Recipes/Recipe.cs @@ -13,6 +13,8 @@ namespace Model { #region Attributes private string _title = ""; + + //private List _reviews; #endregion #region Properties @@ -21,6 +23,8 @@ namespace Model /// public int Id { get; init; } + public List Reviews { get; private set; } + /// /// The Title of the recipe.
/// Set to "No title." when the value passed is null, empty or contain white spaces. @@ -47,15 +51,17 @@ namespace Model /// /// Construct a new recipe. /// - /// The title of the recipe + /// 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 = null, - params PreparationStep[] preparationSteps) - { + /// The steps of the preparation of the meal. + public Recipe(string title, int? id, + List reviews, + params PreparationStep[] preparationSteps) + { Title = title; - PreparationSteps = new List(preparationSteps); - + PreparationSteps = new List(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; + } + + /// + /// + /// + /// The title of the recipe. + public Recipe(string title) + : this(title, null, new List()) + { + } + + /// + /// + /// + /// The title of the recipe. + /// The steps of the preparation of the meal. + public Recipe(string title, params PreparationStep[] preparationSteps) + : this(title, null, new List(), 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; diff --git a/MCTG/Model/Recipes/Review.cs b/MCTG/Model/Recipes/Review.cs index 2c005e5..bd0a988 100644 --- a/MCTG/Model/Recipes/Review.cs +++ b/MCTG/Model/Recipes/Review.cs @@ -7,13 +7,15 @@ using System.Threading.Tasks; namespace Model { - internal class Review + public class Review : IEquatable { private int _stars; private string _content = ""; public int Id { get; init; } + public User Author { get; private set; } + public int Stars { get => _stars; @@ -34,7 +36,7 @@ namespace Model } } - public Review(int? id, int stars, string content) + public Review(User author, int? id, int stars, string content) { if (id == null) { @@ -45,12 +47,38 @@ namespace Model } else Id = (int)id; + Author = author; Stars = stars; Content = content; } - public Review(int stars, string content) : this(null, stars, content) + public Review(User author, int stars, string content) : this(author, null, stars, content) + { + } + + public override string ToString() + { + return $"{Author.Name} {Author.Surname}: [ {Stars} stars ]\n{Content}"; + } + + public bool Equals(Review? other) + { + if (other is null) return false; + return Id.Equals(other.Id); + } + + public override bool Equals(object? obj) + { + if (ReferenceEquals(obj, null)) return false; + if (ReferenceEquals(obj, this)) return true; + if (GetType() != obj.GetType()) return false; + + return Equals(obj); + } + + public override int GetHashCode() { + return Id.GetHashCode(); } } } From da4121b7290df03713a8b8d535b2fc1ccb9d7afc Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Tue, 16 May 2023 15:25:28 +0200 Subject: [PATCH 3/8] correction on build --- MCTG/ConsoleApp/Program.cs | 18 +++++++----------- MCTG/ConsoleApp/Stubs/Stub.cs | 14 +++++++------- .../Model_UnitTests/RecipeCollection_UT.cs | 10 ++++++---- MCTG/Tests/Model_UnitTests/Recipe_UT.cs | 16 +--------------- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index ac9a1e9..2ee01cb 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -13,17 +13,13 @@ Console.WriteLine("Hello, World!\n\n"); Stub stub = new Stub(); -List recipes = stub.LoadRecipes(); -List recipeCollections = stub.LoadRecipeCollection(); - -RecipeCollection? allRecipe = recipeCollections.Find(x => x.Description.Equals("All")); -if (allRecipe == null) - throw new ArgumentException("Load AllRecipe in stub: can't find 'All'."); - -Manager manager = new Manager(allRecipe); - -Recipe? ret = SearcherRecipe.ResearchOn(allRecipe); -Console.WriteLine(ret); +List users = stub.ConstrucList(); +RecipeCollection recipes = new RecipeCollection("all", stub.LoadRecipes().ToArray()); + +Console.WriteLine(recipes); +Console.WriteLine("\n---------------------------\n"); + +recipes[] // press any key to quit Console.ReadKey(); diff --git a/MCTG/ConsoleApp/Stubs/Stub.cs b/MCTG/ConsoleApp/Stubs/Stub.cs index f116321..8ec1b68 100644 --- a/MCTG/ConsoleApp/Stubs/Stub.cs +++ b/MCTG/ConsoleApp/Stubs/Stub.cs @@ -15,24 +15,24 @@ namespace ConsoleApp List stub = new List(); stub.AddRange(new[] { - new Recipe(), + new Recipe(""), new Recipe( title: "Cookies"), new Recipe( - title: "Cookies", id: 23), + title: "Cookies"), new Recipe( - title: "Cookies au chocolat", id: null), + title: "Cookies au chocolat"), new Recipe( - title: "", id: null), + title: ""), new Recipe( - title: "", id: 24), + title: ""), new Recipe( - title: "Cookies", id: 24, + title: "Cookies", preparationSteps: new[]{ new PreparationStep(1) }), new Recipe( - title: "Cookies", id: 26, + title: "Cookies", preparationSteps: new[]{ new PreparationStep(1), new PreparationStep(2, "Faire cuire.") diff --git a/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs b/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs index 36008b1..b79b884 100644 --- a/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs +++ b/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs @@ -17,12 +17,14 @@ namespace Model_UnitTests description: "test recipe", recipes: new[] { - new Recipe(title: "Gateau à la crème", id: 1), - new Recipe(title: "Gateau au chocolat", id: 2), - new Recipe(title: "Gateau aux cerises", id: 3) + new Recipe(title: "Gateau à la crème"), + new Recipe(title: "Gateau au chocolat"), + new Recipe(title: "Gateau aux cerises") }); - Assert.Equal(2, recipes.ResearchByName("chocolat").FirstOrDefault().Id); + Recipe? search_result = recipes.ResearchByName("chocolat").FirstOrDefault(); + Assert.NotNull(search_result); + Assert.Equal("Gateau au chocolat", search_result.Title); } } } diff --git a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs index 9655041..4fdce86 100644 --- a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs +++ b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs @@ -7,22 +7,8 @@ namespace Model_UnitTests [Fact] public void TestVoidConstructor() { - Recipe r = new Recipe(id: 999); // id is given to avoid tests errors with the static atrribute 'idCreator'. + Recipe r = new Recipe(""); // id is given to avoid tests errors with the static atrribute 'idCreator'. Assert.NotNull(r.Title); } - - [Theory] - [InlineData("Cookies", 23, "Cookies", 23)] - [InlineData("Cookies", 1, "Cookies", 1)] - [InlineData("No title.", 1, "", 1)] - public void TestConstructor(string expectedTitle, int expectedId, string title, int? id) - { - Recipe r = new Recipe(title, id); - Assert.NotNull(r.Title); - Assert.Equal(expectedId, r.Id); - Assert.Equal(expectedTitle, r.Title); - } - - } } From 2708d0910775364d8a3582e391c7cea7026e1bdf Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Tue, 16 May 2023 15:28:46 +0200 Subject: [PATCH 4/8] sorry --- MCTG/ConsoleApp/Program.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index 2ee01cb..c67dead 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -14,12 +14,10 @@ Console.WriteLine("Hello, World!\n\n"); Stub stub = new Stub(); List users = stub.ConstrucList(); -RecipeCollection recipes = new RecipeCollection("all", stub.LoadRecipes().ToArray()); - -Console.WriteLine(recipes); -Console.WriteLine("\n---------------------------\n"); - -recipes[] - -// press any key to quit -Console.ReadKey(); +RecipeCollection recipes = new RecipeCollection("all", stub.LoadRecipes().ToArray()); + +Console.WriteLine(recipes); +Console.WriteLine("\n---------------------------\n"); + +// press any key to quit +Console.ReadKey(); From 02c5d5b58332d6ec98c568bfcc1afcdc9d510422 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Tue, 23 May 2023 09:20:41 +0200 Subject: [PATCH 5/8] done reviews --- MCTG/ConsoleApp/Program.cs | 9 ++ MCTG/Model/Recipes/Recipe.cs | 232 +++++++++++++++++------------------ 2 files changed, 125 insertions(+), 116 deletions(-) diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index c67dead..600e837 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -16,8 +16,17 @@ Stub stub = new Stub(); List users = stub.ConstrucList(); RecipeCollection recipes = new RecipeCollection("all", stub.LoadRecipes().ToArray()); +recipes[0].AddReview(new Review(users[1], 1, "bonne recette !1")); +recipes[0].AddReview(new Review(users[1], 1, "bonne recette !2")); +recipes[0].AddReview(new Review(users[1], 4, "bonne recette !3")); +recipes[0].AddReview(new Review(users[1], 5, "bonne recette !4")); +recipes[0].AddReview(new Review(users[1], 3, "bonne recette !5")); +recipes[0].AddReview(new Review(users[1], 2, "bonne recette !6")); + Console.WriteLine(recipes); Console.WriteLine("\n---------------------------\n"); +Console.WriteLine(recipes[0].GetReviews()); + // press any key to quit Console.ReadKey(); diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs index f63760e..c4e1305 100644 --- a/MCTG/Model/Recipes/Recipe.cs +++ b/MCTG/Model/Recipes/Recipe.cs @@ -1,102 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Security.Cryptography; -using System.Text; - -namespace Model -{ - /// - /// Define a Recipe for the preparation of a meal. - /// - public class Recipe : IEquatable - { - #region Attributes - private string _title = ""; - - //private List _reviews; - #endregion - - #region Properties - /// - /// The ID of the recipe - allows you to compare and/or get this item in an easier way. - /// - public int Id { get; init; } - - public List Reviews { get; private set; } - - /// - /// The Title of the recipe.
- /// Set to "No title." when the value passed is null, empty or contain white spaces. - ///
- public string Title - { - get => _title; - set - { - if (string.IsNullOrWhiteSpace(value)) - _title = "No title."; - else - _title = value; - } - } - - /// - /// The steps of the preparation. See: . - /// - public List PreparationSteps { get; set; } - #endregion - - #region Constructors - /// - /// Construct a new recipe. - /// - /// 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, - List reviews, +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Security.Cryptography; +using System.Text; + +namespace Model +{ + /// + /// Define a Recipe for the preparation of a meal. + /// + public class Recipe : IEquatable + { + #region Attributes + private string _title = ""; + + //private List _reviews; + #endregion + + #region Properties + /// + /// The ID of the recipe - allows you to compare and/or get this item in an easier way. + /// + public int Id { get; init; } + + public List Reviews { get; private set; } + + /// + /// The Title of the recipe.
+ /// Set to "No title." when the value passed is null, empty or contain white spaces. + ///
+ public string Title + { + get => _title; + set + { + if (string.IsNullOrWhiteSpace(value)) + _title = "No title."; + else + _title = value; + } + } + + /// + /// The steps of the preparation. See: . + /// + public List PreparationSteps { get; set; } + #endregion + + #region Constructors + /// + /// Construct a new recipe. + /// + /// 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, + List reviews, params PreparationStep[] preparationSteps) { - Title = title; + Title = title; PreparationSteps = new List(preparationSteps); Reviews = reviews; - if (id == null) - { - var randomGenerator = RandomNumberGenerator.Create(); - byte[] data = new byte[16]; - randomGenerator.GetBytes(data); - Id = Math.Abs(BitConverter.ToInt16(data)); - } + if (id == null) + { + var randomGenerator = RandomNumberGenerator.Create(); + byte[] data = new byte[16]; + randomGenerator.GetBytes(data); + Id = Math.Abs(BitConverter.ToInt16(data)); + } else Id = (int)id; - } - + } + /// /// /// - /// The title of the recipe. - public Recipe(string title) - : this(title, null, new List()) - { - } - + /// The title of the recipe. + public Recipe(string title) + : this(title, null, new List()) + { + } + /// /// /// /// The title of the recipe. - /// The steps of the preparation of the meal. - public Recipe(string title, params PreparationStep[] preparationSteps) + /// The steps of the preparation of the meal. + public Recipe(string title, params PreparationStep[] preparationSteps) : this(title, null, new List(), preparationSteps) { - } - #endregion - - #region Methods - + } + #endregion + + #region Methods + public void AddReview(Review review) - => Reviews.Add(review); - + => Reviews.Add(review); + public string GetReviews() { StringBuilder sb = new StringBuilder("Reviews:\n------------------------------\n"); @@ -105,36 +105,36 @@ namespace Model sb.AppendLine(review.ToString()); } return sb.ToString(); - } - - public virtual bool Equals(Recipe? other) - { - if (other == null) return false; - if (other == this) return true; - return Title.Equals(other.Title) && PreparationSteps.Equals(other.PreparationSteps); - } - - public override bool Equals(object? obj) - { - var item = obj as Recipe; - if (item == null) return false; - return Equals(obj); - } - - public override int GetHashCode() - { - return Id.GetHashCode(); - } - - public override string ToString() - { - StringBuilder sb = new StringBuilder($"[Recipe n°{Id}] - {Title}\n"); - foreach (PreparationStep ps in PreparationSteps) - { - sb.AppendFormat("\t* {0}\n", ps.ToString()); - } - return sb.ToString(); - } - #endregion - } -} + } + + public virtual bool Equals(Recipe? other) + { + if (other == null) return false; + if (other == this) return true; + return Title.Equals(other.Title) && PreparationSteps.Equals(other.PreparationSteps); + } + + public override bool Equals(object? obj) + { + var item = obj as Recipe; + if (item == null) return false; + return Equals(obj); + } + + public override int GetHashCode() + { + return Id.GetHashCode(); + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder($"[Recipe n°{Id}] - {Title}\n"); + foreach (PreparationStep ps in PreparationSteps) + { + sb.AppendFormat("\t* {0}\n", ps.ToString()); + } + return sb.ToString(); + } + #endregion + } +} From e9a78a4874faa5ca5f946dd184af44ae010291e8 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Tue, 23 May 2023 09:51:45 +0200 Subject: [PATCH 6/8] cm bf m user for data persistance correction --- MCTG/DataPersistence/DataContractJSON.cs | 7 ++++++- MCTG/DataPersistence/DataContractXML.cs | 7 ++++++- MCTG/Model/Recipes/Recipe.cs | 22 ++++++++++++++++++++++ MCTG/Model/Recipes/Review.cs | 8 ++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) 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 From ffd3b1cb76a01fe87f202c28c4c94a20f6864080 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Tue, 23 May 2023 09:58:39 +0200 Subject: [PATCH 7/8] won't build until fix datapersistance in User --- MCTG/Model/Recipes/Review.cs | 10 +- MCTG/Model/User/User.cs | 304 +++++++++++++++++------------------ 2 files changed, 160 insertions(+), 154 deletions(-) diff --git a/MCTG/Model/Recipes/Review.cs b/MCTG/Model/Recipes/Review.cs index caf19cc..198c1b3 100644 --- a/MCTG/Model/Recipes/Review.cs +++ b/MCTG/Model/Recipes/Review.cs @@ -21,7 +21,7 @@ namespace Model [DataMember(Name = "id")] public int Id { get; init; } - [DataMember(Name = "author")] + [DataMember(Name = "user")] public User Author { get; private set; } public int Stars @@ -60,7 +60,13 @@ namespace Model Content = content; } - public Review(User author, int stars, string content) : this(author, null, stars, content) + public Review(User author, int stars, string content) + : this(author, null, stars, content) + { + } + + public Review(int stars, string content) + : this(new User("...", "...", "...@..."), null, stars, content) { } diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index cbec8c4..97bd95e 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -1,157 +1,157 @@ -using System; -using System.Collections.Generic; -using System.Collections; -using System.Collections.ObjectModel; -using System.Threading.Tasks; -using System.Runtime.CompilerServices; -using System.Text.RegularExpressions; - -namespace Model -{ - /// - /// A user is an entity with a name, a surname, mail, profilePict and a list of priority. - /// This user can login with a Id and password - /// - public class User : IEquatable - { - #region Private Attributes - - private string name=""; - private string surname=""; - private string mail = ""; - private string picture = ""; - private string password = ""; - //private string defaultUserSavePath = ""; - private List priorities; - #endregion - - #region Properties - - /// - /// Property to get Name of users and a setter - /// - /// Setter have Exception which is trigger when Name is null - public string Name - { - get { return name; } - private set - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Nom vide!"); - } - name = value; - } - } - - /// - /// Property to get Surname of users and a setter - /// - /// Setter have Exception which is trigger when Surname is null - public string Surname - { - get { return surname; } - private set - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Prénom vide!"); - } - surname = value; - } - } - - /// - /// Property to get mail of users and a setter - /// - /// User's mail will serve to log the user. So there's no setter, just an init. User will enter one time his email at his - /// account creation. - public string Mail - { - get { return mail; } - private init - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Email vide!"); - } - mail = value; - } - } - - /// - /// Property to initiate password, change it, and - /// - public string Password - { - get { return password; } - - set { password = value; } - } - - /// - /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" - /// when the value is null. - /// - public string ProfilPict - { - get => picture; - set => picture = value; - - } - - /// - /// This is the list of priorities specific tu the user. This list is initiate - /// by default. User could change it at will. - /// - - public List Priorities - { - get => priorities; - set=> priorities = value; - } - +using System; +using System.Collections.Generic; +using System.Collections; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; + +namespace Model +{ + /// + /// A user is an entity with a name, a surname, mail, profilePict and a list of priority. + /// This user can login with a Id and password + /// + public class User : IEquatable + { + #region Private Attributes + + private string name=""; + private string surname=""; + private string mail = ""; + private string picture = ""; + private string password = ""; + //private string defaultUserSavePath = ""; + private List priorities; + #endregion + + #region Properties + + /// + /// Property to get Name of users and a setter + /// + /// Setter have Exception which is trigger when Name is null + public string Name + { + get { return name; } + private set + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Nom vide!"); + } + name = value; + } + } + + /// + /// Property to get Surname of users and a setter + /// + /// Setter have Exception which is trigger when Surname is null + public string Surname + { + get { return surname; } + private set + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Prénom vide!"); + } + surname = value; + } + } + + /// + /// Property to get mail of users and a setter + /// + /// User's mail will serve to log the user. So there's no setter, just an init. User will enter one time his email at his + /// account creation. + public string Mail + { + get { return mail; } + private init + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Email vide!"); + } + mail = value; + } + } + + /// + /// Property to initiate password, change it, and + /// + public string Password + { + get { return password; } + + set { password = value; } + } + + /// + /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" + /// when the value is null. + /// + public string ProfilPict + { + get => picture; + set => picture = value; + + } + + /// + /// This is the list of priorities specific tu the user. This list is initiate + /// by default. User could change it at will. + /// + + public List Priorities + { + get => priorities; + set=> priorities = value; + } + public override bool Equals(object? obj) { if (obj == null) return false; if (obj == this) return true; return Equals(obj); - } - public bool Equals(User? other) - { - if (other == null ) return false; - return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); - } - - - #endregion - - - #region Constructors - - /// - /// Construtors of user. - /// - /// The name of the user - /// The surname of the user - /// The user needs an email to login. - public User(string name, string surname, string mail) - { - Name = name; - Surname = surname; - Mail = mail; - priorities = new List { - Priority.Gourmet, - Priority.Economic, - Priority.Fast, - Priority.Light, - Priority.Easy}; - ProfilPict = picture; - - } - - #endregion - - - } -} + } + public bool Equals(User? other) + { + if (other == null ) return false; + return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); + } + + + #endregion + + + #region Constructors + + /// + /// Construtors of user. + /// + /// The name of the user + /// The surname of the user + /// The user needs an email to login. + public User(string name, string surname, string mail) + { + Name = name; + Surname = surname; + Mail = mail; + priorities = new List { + Priority.Gourmet, + Priority.Economic, + Priority.Fast, + Priority.Light, + Priority.Easy}; + ProfilPict = picture; + + } + + #endregion + + + } +} From a93132f71297a7843f70321fb35694ff42eb3fc2 Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Tue, 23 May 2023 14:43:13 +0200 Subject: [PATCH 8/8] correction of the last merge --- MCTG/Model/User/User.cs | 286 ++++++++++++++++++++-------------------- 1 file changed, 146 insertions(+), 140 deletions(-) diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index 6f930e4..776cc60 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -1,114 +1,114 @@ -using System; -using System.Collections.Generic; -using System.Collections; -using System.Collections.ObjectModel; -using System.Threading.Tasks; -using System.Runtime.CompilerServices; -using System.Text.RegularExpressions; +using System; +using System.Collections.Generic; +using System.Collections; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; using System.Text; - -namespace Model -{ - /// - /// A user is an entity with a name, a surname, mail, profilePict and a list of priority. - /// This user can login with a Id and password - /// - public class User : IEquatable - { - #region Private Attributes - - private string name=""; - private string surname=""; - private string mail = ""; - private string picture = ""; + +namespace Model +{ + /// + /// 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 + /// + public class User : IEquatable + { + #region Private Attributes + + private string name=""; + private string surname=""; + private string mail = ""; + private string picture = ""; private int password ; - private List priorities; - #endregion - - #region Properties - - /// - /// Property to get Name of users and a setter - /// - /// Setter have Exception which is trigger when Name is null - public string Name - { - get { return name; } - private set - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Nom vide!"); - } - name = value; - } - } - - /// - /// Property to get Surname of users and a setter - /// - /// Setter have Exception which is trigger when Surname is null - public string Surname - { - get { return surname; } - private set - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Prénom vide!"); - } - surname = value; - } - } - - /// - /// Property to get mail of users and a setter - /// - /// User's mail will serve to log the user. So there's no setter, just an init. User will enter one time his email at his - /// account creation. - public string Mail - { - get { return mail; } - private init - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Email vide!"); - } - mail = value; - } - } - + private List priorities; + #endregion + + #region Properties + + /// + /// Property to get Name of users and a setter + /// + /// Setter have Exception which is trigger when Name is null + public string Name + { + get { return name; } + private set + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Nom vide!"); + } + name = value; + } + } + + /// + /// Property to get Surname of users and a setter + /// + /// Setter have Exception which is trigger when Surname is null + public string Surname + { + get { return surname; } + private set + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Prénom vide!"); + } + surname = value; + } + } + + /// + /// Property to get mail of users and a setter + /// + /// User's mail will serve to log the user. So there's no setter, just an init. User will enter one time his email at his + /// account creation. + public string Mail + { + get { return mail; } + private init + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Email vide!"); + } + mail = value; + } + } + public int Password - { + { get => password; set => password = value; - } - - - /// - /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" - /// when the value is null. - /// - public string ProfilPict - { - get => picture; - set => picture = value; - - } - - /// - /// This is the list of priorities specific tu the user. This list is initiate - /// by default. User could change it at will. - /// - - public List Priorities - { - get => priorities; - set=> priorities = value; - } - + } + + + /// + /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" + /// when the value is null. + /// + public string ProfilPict + { + get => picture; + set => picture = value; + + } + + /// + /// This is the list of priorities specific tu the user. This list is initiate + /// by default. User could change it at will. + /// + + public List Priorities + { + get => priorities; + set=> priorities = value; + } + public override bool Equals(object? other) { if (other == null) return false; @@ -117,41 +117,47 @@ namespace Model } public bool Equals(User? other) - { + { if (other == null) return false; - return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); - } - - - #endregion - - - #region Constructors - - /// - /// Construtors of user. - /// - /// The name of the user - /// The surname of the user - /// The user needs an email to login. + return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + + #endregion + + + #region Constructors + + /// + /// Construtors of user. + /// + /// The name of the user + /// The surname of the user + /// The user needs an email to login. public User(string name, string surname, string mail, int password) - { - Name = name; - Surname = surname; - Mail = mail; + { + Name = name; + Surname = surname; + Mail = mail; Password = password; - priorities = new List { - Priority.Gourmet, - Priority.Economic, - Priority.Fast, - Priority.Light, - Priority.Easy}; - ProfilPict = picture; - - } - - #endregion - - - } -} + priorities = new List { + Priority.Gourmet, + Priority.Economic, + Priority.Fast, + Priority.Light, + Priority.Easy}; + ProfilPict = picture; + + } + + + + #endregion + + + } +}