Skip to content

Commit

Permalink
Merge pull request #37 from kzi-nastava/feat/id-attribute
Browse files Browse the repository at this point in the history
[Update] Enhancing classes with Id attribute
  • Loading branch information
natasakasikovic authored Mar 29, 2024
2 parents ea196b9 + e846d73 commit 184baed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
31 changes: 21 additions & 10 deletions LangLang/Core/Model/Profile.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LangLang.Core.Model
{
class Profile
public class Profile
{
// Attributes
private int _id;
private string _name;
private string _lastName;
private UserGender _gender;
Expand All @@ -19,6 +16,12 @@ class Profile
private UserType _role;

// Properties
public int Id
{
get { return _id; }
set { _id = value; }
}

public string Name
{
get { return _name; }
Expand Down Expand Up @@ -68,8 +71,9 @@ public UserType Role
}

// Constructor
public Profile(string name, string lastName, UserGender gender, DateTime dateOfBirth, string phoneNumber, string email, string password, UserType role)
public Profile(int id, string name, string lastName, UserGender gender, DateTime dateOfBirth, string phoneNumber, string email, string password, UserType role)
{
Id = id;
Name = name;
LastName = lastName;
Gender = gender;
Expand All @@ -79,14 +83,21 @@ public Profile(string name, string lastName, UserGender gender, DateTime dateOfB
Password = password;
Role = role;
}

public Profile() { }

/// <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)
public Profile(string id, string name, string lastName, string gender, string dateOfBirth, string phoneNumber, string email, string password, string role)
{
try
{
Id = int.Parse(id);
}
catch (FormatException ex)
{
throw new FormatException("Unable to convert the Id to integer. ", ex);
}

if (!Enum.TryParse(gender, out _gender)
|| !Enum.TryParse(role, out _role)
Expand All @@ -104,7 +115,7 @@ public Profile(string name, string lastName, string gender, string dateOfBirth,

public override string ToString()
{
return string.Join("|", new object[] { Name, LastName, Gender, DateOfBirth.ToString("yyyy-MM-dd"), PhoneNumber, Email, Password, Role });
return string.Join("|", new object[] { Id, Name, LastName, Gender, DateOfBirth.ToString("yyyy-MM-dd"), PhoneNumber, Email, Password, Role });
}

}
Expand Down
12 changes: 6 additions & 6 deletions LangLang/Core/Model/Student.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace LangLang.Core.Model
{
class Student : ISerializable
public class Student : ISerializable
{

private Profile _profile;
Expand All @@ -29,20 +29,20 @@ public bool CanModifyInfo
}
public Student() { }

Check warning on line 30 in LangLang/Core/Model/Student.cs

View workflow job for this annotation

GitHub Actions / build

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

Check warning on line 30 in LangLang/Core/Model/Student.cs

View workflow job for this annotation

GitHub Actions / build

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

public Student(string name, string lastName, UserGender gender, DateTime dateOfBirth, string phoneNumber, string email, string password, UserType role, string professionalQualification)
public Student(int id, string name, string lastName, UserGender gender, DateTime dateOfBirth, string phoneNumber, string email, string password, UserType role, string professionalQualification)

Check warning on line 32 in LangLang/Core/Model/Student.cs

View workflow job for this annotation

GitHub Actions / build

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

Check warning on line 32 in LangLang/Core/Model/Student.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_professionalQualification' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
{
Profile = new Profile(name, lastName, gender, dateOfBirth, phoneNumber, email, password, role);
Profile = new Profile(id, name, lastName, gender, dateOfBirth, phoneNumber, email, password, role);
ProfessionalQualification = professionalQualification;
CanModifyInfo = true;
}

public void FromCSV(string[] values)
{
Profile = new Profile(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]);
Profile = new Profile(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8]);

ProfessionalQualification = values[8];
ProfessionalQualification = values[9];

if (!bool.TryParse(values[9], out bool canModifyInfo))
if (!bool.TryParse(values[10], out bool canModifyInfo))
{
throw new FormatException("CanModifyInfo token is not in the correct format.");
}
Expand Down

0 comments on commit 184baed

Please sign in to comment.