Skip to content

Commit

Permalink
Merge pull request #61 from kzi-nastava/feat/TutorDAO-fix
Browse files Browse the repository at this point in the history
Feat/tutor dao fix
  • Loading branch information
anasinik authored Mar 30, 2024
2 parents 2acd5e8 + 944eaed commit 6312e0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
25 changes: 19 additions & 6 deletions LangLang/Core/Model/DAO/TutorDAO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LangLang.Core.DAO
{
public class TutorDAO : Subject
{
private readonly List<Tutor> _tutors;
private readonly Dictionary<int, Tutor> _tutors;
private readonly Repository<Tutor> _repository;

public TutorDAO()
Expand All @@ -22,21 +22,21 @@ private int GenerateId()
return _tutors.Count + 1;
}

private Tutor Get(int id)
private Tutor? Get(int id)
{
return _tutors.Find(t => t.Profile.Id == id);
return _tutors[id];
}

public Tutor Add(Tutor tutor)
{
tutor.Profile.Id = GenerateId();
_tutors.Add(tutor);
_tutors.Add(tutor.Profile.Id, tutor);
_repository.Save(_tutors);
NotifyObservers();
return tutor;
}

public Tutor Update(Tutor tutor)
public Tutor? Update(Tutor tutor)
{
Tutor oldTutor = Get(tutor.Profile.Id);
if (oldTutor == null) { return null; }
Expand All @@ -55,8 +55,21 @@ public Tutor Update(Tutor tutor)
return oldTutor;
}

// TODO: implement GetAllTutors and Remove method
public Dictionary<int, Tutor> GetAllTutors()
{
return _tutors;
}

public Tutor? Remove(int id)
{
Tutor tutor = Get(id);
if (tutor == null) return null;

_tutors.Remove(tutor.Profile.Id);
_repository.Save(_tutors);
NotifyObservers();
return tutor;
}
}
}

5 changes: 5 additions & 0 deletions LangLang/Core/Model/Tutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public Tutor()
_profile = new();
}

public int Id
{
get { return Profile.Id; }
}

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]);
Expand Down

0 comments on commit 6312e0c

Please sign in to comment.