From c74ec389e19d81fe677d8d20cbe775eb89c62406 Mon Sep 17 00:00:00 2001 From: Natasa Kasikovic~ Date: Sat, 30 Mar 2024 00:50:31 +0100 Subject: [PATCH] [Update] Implementation of Tutor class --- LangLang/Core/Model/Tutor.cs | 82 +++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/LangLang/Core/Model/Tutor.cs b/LangLang/Core/Model/Tutor.cs index 512eb7e9..4af24a89 100644 --- a/LangLang/Core/Model/Tutor.cs +++ b/LangLang/Core/Model/Tutor.cs @@ -1,43 +1,74 @@ -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; + namespace LangLang.Core.Model { - class Tutor + public class Tutor : ISerializable { - // Profile attribute of type Profile private Profile _profile { get; set; } private Dictionary _languageSkills { get; set; } + private DateTime _employmentDate { get; set; } - // Constructor - public Tutor() - { - // Initialize empty profile and language skills - _profile = new Profile(); - _profile.Role = UserType.Tutor; - _languageSkills = new Dictionary(); - } - public Tutor(Profile profile, Dictionary languageSkills) - { - _profile = profile; + public Tutor(int id, string name, string lastName, UserGender gender, DateTime dateOfBirth, string phoneNumber, string email, string password, UserType role, DateTime employmentDate, Dictionary languageSkills) { + _profile = new Profile(id, name, lastName, gender, dateOfBirth, phoneNumber, email, password, role); + _employmentDate = employmentDate; _languageSkills = languageSkills; - } + } - //Getters and setters - public Profile Profile + public void FromCSV(string[] values) { - get { return _profile; } - private set { _profile = value; } + _profile = new Profile(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8]); + DateTime employmentDate; + + 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."); + } + _employmentDate = employmentDate; + + 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 Dictionary LanguageSkills + + public string[] ToCSV() { - get { return _languageSkills; } - private set { _languageSkills = value; } + string[] csvValues = + { + _profile.ToString(), + _employmentDate.ToString("yyyy-MM-dd"), + DictToCSV(_languageSkills) + }; + + return csvValues; + } + + public string DictToCSV(Dictionary 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 GetCourses(ref Dictionary courses) { @@ -63,3 +94,4 @@ public List GetExamSlots(ref Dictionary examSlots) //add searchCourses and searchExamSlots } } + \ No newline at end of file