From 0f14affae806fc3d8db3d782249c815086daf9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20=C5=A0inik?= Date: Fri, 29 Mar 2024 09:23:08 +0100 Subject: [PATCH 1/2] [Update] Implementation of class Profile --- LangLang/Core/Model/Profile.cs | 53 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/LangLang/Core/Model/Profile.cs b/LangLang/Core/Model/Profile.cs index ddf57ba6..cedc9378 100644 --- a/LangLang/Core/Model/Profile.cs +++ b/LangLang/Core/Model/Profile.cs @@ -9,62 +9,62 @@ namespace LangLang.Core.Model class Profile { // Attributes - private string name; - private string lastName; - private UserGender gender; - private DateTime dateOfBirth; - private string phoneNumber; - private string email; - private string password; - private UserType role; + private string _name; + private string _lastName; + private UserGender _gender; + private DateTime _dateOfBirth; + private string _phoneNumber; + private string _email; + private string _password; + private UserType _role; // Properties public string Name { - get { return name; } - set { name = value; } + get { return _name; } + set { _name = value; } } public string LastName { - get { return lastName; } - set { lastName = value; } + get { return _lastName; } + set { _lastName = value; } } public UserGender Gender { - get { return gender; } - set { gender = value; } + get { return _gender; } + set { _gender = value; } } public DateTime DateOfBirth { - get { return dateOfBirth; } - set { dateOfBirth = value; } + get { return _dateOfBirth; } + set { _dateOfBirth = value; } } public string PhoneNumber { - get { return phoneNumber; } - set { phoneNumber = value; } + get { return _phoneNumber; } + set { _phoneNumber = value; } } public string Email { - get { return email; } - set { email = value; } + get { return _email; } + set { _email = value; } } public string Password { - get { return password; } - set { password = value; } + get { return _password; } + set { _password = value; } } public UserType Role { - get { return role; } - set { role = value; } + get { return _role; } + set { _role = value; } } // Constructor @@ -80,5 +80,10 @@ public Profile(string name, string lastName, UserGender gender, DateTime dateOfB Role = role; } + public override string ToString() + { + return string.Join("|", new object[] { Name, LastName, Gender, DateOfBirth.ToString("yyyy-MM-dd"), PhoneNumber, Email, Password, Role }); + } + } } From f7fc836247cbb0420d45f037bc1719cedabbd12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20=C5=A0inik?= Date: Fri, 29 Mar 2024 14:25:51 +0100 Subject: [PATCH 2/2] [Update] Implementation of Profile class --- LangLang/Core/Model/Profile.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/LangLang/Core/Model/Profile.cs b/LangLang/Core/Model/Profile.cs index cedc9378..f8f6e5b1 100644 --- a/LangLang/Core/Model/Profile.cs +++ b/LangLang/Core/Model/Profile.cs @@ -80,6 +80,27 @@ public Profile(string name, string lastName, UserGender gender, DateTime dateOfB Role = role; } + /// + /// Constructor for initializing after parsing data loaded from file. + /// + /// Thrown when one or more tokens (date, role or gender) are not in the correct format. + public Profile(string name, string lastName, string gender, string dateOfBirth, string phoneNumber, string email, string password, string role) + { + + if (!Enum.TryParse(gender, out _gender) + || !Enum.TryParse(role, out _role) + || !DateTime.TryParseExact(dateOfBirth, "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out _dateOfBirth)) + { + throw new FormatException("One or more tokens are not in the correct format."); + } + + Name = name; + LastName = lastName; + PhoneNumber = phoneNumber; + Email = email; + Password = password; + } + public override string ToString() { return string.Join("|", new object[] { Name, LastName, Gender, DateOfBirth.ToString("yyyy-MM-dd"), PhoneNumber, Email, Password, Role });