Skip to content

Commit

Permalink
Merge pull request #44 from kzi-nastava/feat/Tutor
Browse files Browse the repository at this point in the history
Update implementation of Tutor class
  • Loading branch information
anasinik authored Mar 30, 2024
2 parents 1785587 + fd0b6f5 commit 6b79292
Showing 1 changed file with 82 additions and 22 deletions.
104 changes: 82 additions & 22 deletions LangLang/Core/Model/Tutor.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,102 @@
using System;
using LangLang.Core.Repository.Serialization;
using LangLang.Core.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using LangLang.Core.Model;
using System.Data;
using System.Reflection;

namespace LangLang.Core.Model
{
class Tutor
public class Tutor : ISerializable
{
// Profile attribute of type Profile
private Profile _profile { get; set; }
private Dictionary<string, LanguageLevel> _languageSkills { get; set; }
private Dictionary<string, LanguageLevel> _languageSkills;

// Constructor
public Tutor()
private DateTime _employmentDate;

private Profile _profile;

public Dictionary<string, LanguageLevel> LanguageSkills
{
// Initialize empty profile and language skills
_profile = new Profile();
_profile.Role = UserType.Tutor;
_languageSkills = new Dictionary<string, LanguageLevel>();
get { return _languageSkills; }
set { _languageSkills = value; }
}
public Tutor(Profile profile, Dictionary<string, LanguageLevel> languageSkills)
public DateTime EmploymentDate
{
_profile = profile;
_languageSkills = languageSkills;
get { return _employmentDate; }
set { _employmentDate = value; }
}

//Getters and setters
public Profile Profile
{
get { return _profile; }
private set { _profile = value; }
}
public Dictionary<string, LanguageLevel> LanguageSkills

public Tutor(int id, string name, string lastName, UserGender gender, DateTime dateOfBirth, string phoneNumber, string email, string password, UserType role, DateTime employmentDate, Dictionary<string, LanguageLevel> languageSkills) {
_profile = new Profile(id, name, lastName, gender, dateOfBirth, phoneNumber, email, password, role);
_employmentDate = employmentDate;
_languageSkills = languageSkills;
}

public Tutor()
{
get { return _languageSkills; }
private set { _languageSkills = value; }
_languageSkills = new Dictionary<string, LanguageLevel>();
_employmentDate = DateTime.MinValue;
_profile = new();
}

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

if (!DateTime.TryParseExact(values[9], "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out _employmentDate))
{
throw new FormatException("Date is not in the correct format.");
}

for (int i = 10; i < values.Length; i++)
{
string[] languageSkill = values[i].Split(',');

if (languageSkill.Length != 2)
{
throw new FormatException("Language and skill pair is not in the correct format.");
}
LanguageLevel level;
if (Enum.TryParse(languageSkill[1], out level))
{
_languageSkills.Add(languageSkill[0], level);
}
}
}

public string[] ToCSV()
{
string[] csvValues =
{
_profile.ToString(),
_employmentDate.ToString("yyyy-MM-dd"),
DictToCSV(_languageSkills)
};

return csvValues;
}

public string DictToCSV(Dictionary<string, LanguageLevel> skills)
{
StringBuilder sb = new StringBuilder();
var length = skills.Count();
foreach (var skill in skills)
{
sb.Append(skill.Key).Append(",").Append(skill.Value);
if (--length > 0) sb.Append("|");
}
return sb.ToString();
}



/*
public List<Course> GetCourses(ref Dictionary<int, Course> courses)
{
Expand All @@ -63,3 +122,4 @@ public List<ExamSlot> GetExamSlots(ref Dictionary<int, ExamSlot> examSlots)
//add searchCourses and searchExamSlots
}
}

0 comments on commit 6b79292

Please sign in to comment.