diff --git a/MCTG/Model/PreparationStep.cs b/MCTG/Model/PreparationStep.cs index 55336d2..95d15ca 100644 --- a/MCTG/Model/PreparationStep.cs +++ b/MCTG/Model/PreparationStep.cs @@ -59,6 +59,13 @@ namespace Model return Order.Equals(other.Order) && Description.Equals(other.Description); } + public override bool Equals(object? obj) + { + var item = obj as PreparationStep; + if (item == null) return false; + return Equals(obj); + } + public override int GetHashCode() { return Order.GetHashCode() + Description.GetHashCode(); diff --git a/MCTG/Model/Recipe.cs b/MCTG/Model/Recipe.cs index 8f69fb9..9d65bf9 100644 --- a/MCTG/Model/Recipe.cs +++ b/MCTG/Model/Recipe.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Security.Cryptography; using System.Text; namespace Model @@ -54,8 +55,14 @@ namespace Model { Title = title; PreparationSteps = new List(preparationSteps); - - if (id == null) Id = new Random().Next(); + + 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; } #endregion @@ -68,6 +75,13 @@ namespace Model 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(); diff --git a/MCTG/Model/RecipeCollection.cs b/MCTG/Model/RecipeCollection.cs index 6575729..3592bb8 100644 --- a/MCTG/Model/RecipeCollection.cs +++ b/MCTG/Model/RecipeCollection.cs @@ -128,6 +128,13 @@ namespace Model return _description.Equals(other.Description) && _recipes.Equals(other._recipes); } + public override bool Equals(object? obj) + { + var item = obj as RecipeCollection; + if (item == null) return false; + return Equals(obj); + } + public override int GetHashCode() { return _recipes.GetHashCode();