Skip to content

Commit

Permalink
[Update] Implementation of TutorDAO to work with dict instead of list
Browse files Browse the repository at this point in the history
  • Loading branch information
natasakasikovic committed Mar 30, 2024
1 parent 1f89ce8 commit 944eaed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 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 @@ -24,13 +24,13 @@ private int GenerateId()

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;
Expand All @@ -55,7 +55,7 @@ public Tutor Add(Tutor tutor)
return oldTutor;
}

public List<Tutor> GetAllTutors()
public Dictionary<int, Tutor> GetAllTutors()
{
return _tutors;
}
Expand All @@ -65,7 +65,7 @@ public List<Tutor> GetAllTutors()
Tutor tutor = Get(id);
if (tutor == null) return null;

_tutors.Remove(tutor);
_tutors.Remove(tutor.Profile.Id);
_repository.Save(_tutors);
NotifyObservers();
return tutor;
Expand Down
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 944eaed

Please sign in to comment.