Skip to content

Commit

Permalink
Merge pull request #90 from kzi-nastava/feat/CourseController-Update
Browse files Browse the repository at this point in the history
[Update] Course and CourseController Classes
  • Loading branch information
DusicaPesic authored Mar 31, 2024
2 parents 40d3f41 + dc851cc commit 49e723a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
22 changes: 19 additions & 3 deletions LangLang/Core/Controller/CourseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ public void Subscribe(IObserver observer)
_courses.Subscribe(observer);
}


// Method checks if the course is valid for updating or canceling
public bool IsCourseValid(int courseId)
{
Course course = GetAllCourses()[id];
TimeSpan difference = course.StartDate - DateTime.Now;
Course course = GetAllCourses()[courseId];
TimeSpan difference = course.StartDateTime - DateTime.Now;
return difference.TotalDays < 7;
}

// Method checks if a certain course is available for the student
public bool IsCourseAvailable(int courseId)
{
Course course = GetAllCourses()[courseId];
TimeSpan difference = course.StartDate - DateTime.Now;
TimeSpan difference = course.StartDateTime - DateTime.Now;
if (difference.TotalDays < 7)
{
if (course.Online)
Expand Down Expand Up @@ -81,5 +82,20 @@ public Dictionary<int, Course> GetCoursesByTutor(Tutor tutor)
return coursesByTutor;
}

public Dictionary<int, Course> GetCoursesByTutor(int tutorId)
{
Dictionary<int, Course> coursesByTutor = new Dictionary<int, Course>();

foreach (Course course in GetAllCourses().Values)
{
if (course.TutorId == tutorId)
{
coursesByTutor[course.Id] = course;
}
}

return coursesByTutor;
}

}
}
18 changes: 9 additions & 9 deletions LangLang/Core/Model/Course.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Course : ISerializable
private bool _online;
private int _numberOfStudents;
private int _maxStudents;
private DateTime _startDate;
private DateTime _startDateTime;

// Properties

Expand Down Expand Up @@ -77,16 +77,16 @@ public int MaxStudents
set { _maxStudents = value; }
}

public DateTime StartDate
public DateTime StartDateTime
{
get { return _startDate; }
set { _startDate = value; }
get { return _startDateTime; }
set { _startDateTime = value; }
}

// Constructors

public Course(int id, int tutorId, string language, LanguageLevel level, int numberOfWeeks, List<WeekDays> days,

Check warning on line 88 in LangLang/Core/Model/Course.cs

View workflow job for this annotation

GitHub Actions / build

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

Check warning on line 88 in LangLang/Core/Model/Course.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_days' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
bool online, int maxStudents, DateTime startDate)
bool online, int maxStudents, DateTime startDateTime)
{
Id = id;
TutorId = tutorId;
Expand All @@ -97,7 +97,7 @@ public Course(int id, int tutorId, string language, LanguageLevel level, int num
Online = online;
NumberOfStudents = 0;
MaxStudents = maxStudents;
StartDate = startDate;
StartDateTime = startDateTime;
}

public Course()

Check warning on line 103 in LangLang/Core/Model/Course.cs

View workflow job for this annotation

GitHub Actions / build

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

Check warning on line 103 in LangLang/Core/Model/Course.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_days' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
Expand All @@ -118,7 +118,7 @@ public string ToString()
sbDays.Remove(sbDays.Length - 1, 1);
}

return $"ID: {Id,5} | Language: {Language,20} | Level: {Level,5} | NumberOfWeeks: {NumberOfWeeks,5} | Days: {sbDays, 10} | Online: {Online,5} | NumberOfStudents : {NumberOfStudents,5} | MaxStudents : {MaxStudents,5} | CreationDate : {StartDate,10} |";
return $"ID: {Id,5} | Language: {Language,20} | Level: {Level,5} | NumberOfWeeks: {NumberOfWeeks,5} | Days: {sbDays, 10} | Online: {Online,5} | NumberOfStudents : {NumberOfStudents,5} | MaxStudents : {MaxStudents,5} | StartDateTime : {StartDateTime,10} |";
}

public string[] ToCSV()
Expand All @@ -145,7 +145,7 @@ public string[] ToCSV()
Online.ToString(),
NumberOfStudents.ToString(),
MaxStudents.ToString(),
StartDate.ToString()
StartDateTime.ToString()
};
return csvValues;
}
Expand All @@ -168,7 +168,7 @@ public void FromCSV(string[] values)
Online = bool.Parse(values[5]);
NumberOfStudents = int.Parse(values[6]);
MaxStudents = int.Parse(values[7]);
StartDate = DateTime.Parse(values[8]);
StartDateTime = DateTime.Parse(values[8]);
}
}
}

0 comments on commit 49e723a

Please sign in to comment.