Skip to content

Commit

Permalink
Merge pull request #28 from kzi-nastava/origin/feat/User
Browse files Browse the repository at this point in the history
[Update] Implementation of Profile
  • Loading branch information
natasakasikovic authored Mar 29, 2024
2 parents 1f4d725 + f7fc836 commit 999d5bd
Showing 1 changed file with 50 additions and 24 deletions.
74 changes: 50 additions & 24 deletions LangLang/Core/Model/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -81,5 +81,31 @@ public Profile(string name, string lastName, UserGender gender, DateTime dateOfB
}
public Profile() { }

Check warning on line 82 in LangLang/Core/Model/Profile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_name' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 82 in LangLang/Core/Model/Profile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_lastName' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

/// <summary>
/// Constructor for initializing after parsing data loaded from file.
/// </summary>
/// <exception cref="FormatException">Thrown when one or more tokens (date, role or gender) are not in the correct format.</exception>
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 });
}

}
}

0 comments on commit 999d5bd

Please sign in to comment.