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) + { + } + } +}