Skip to content

Commit

Permalink
fix: inconsistency in names after renaming certain identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
natasakasikovic committed Jun 14, 2024
1 parent 23ab642 commit afe0cdd
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 92 deletions.
8 changes: 5 additions & 3 deletions LangLang/BusinessLogic/UseCases/ExamApplicationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ExamApplication Add(ExamApplication application)

var examService = new ExamSlotService();
ExamSlot? exam = examService.Get(application.ExamSlotId);
examService.AddStudent(exam);
examService.IncrementApplicants(exam);
_applications.Add(application);
return application;
}
Expand All @@ -52,7 +52,7 @@ public ExamApplication Add(ExamApplication application)

var examService = new ExamSlotService();
ExamSlot? exam = examService.Get(application.ExamSlotId);
examService.RemoveStudent(exam);
examService.DecrementApplicants(exam);
_applications.Delete(application.Id);
return application;
}
Expand Down Expand Up @@ -104,7 +104,9 @@ public bool CancelApplication(ExamApplication application)
}
private bool CanBeCanceled(ExamSlot exam)
{
return exam.TimeSlot.Time.Date - DateTime.Now.Date > TimeSpan.FromDays(Constants.EXAM_CANCELATION_PERIOD);
var timeService = new TimeSlotService();
var timeSlot = timeService.Get(exam.TimeSlotId);
return timeSlot.Time.Date - DateTime.Now.Date > TimeSpan.FromDays(Constants.EXAM_CANCELATION_PERIOD);
}

public bool HasApplied(Student student, ExamSlot exam)
Expand Down
12 changes: 7 additions & 5 deletions LangLang/BusinessLogic/UseCases/ExamResultService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ public bool HasPreliminaryResults(Student student)
}
public bool IsResultForCourse(ExamResult result,Course course)
{
ExamSlotService examsService = new();
ExamSlot exam = examsService.Get(result.ExamSlotId);
if(exam.Language == course.Language && exam.Level == course.Level)
{
var examService = new ExamSlotService();
var languageService = new LanguageLevelService();

ExamSlot exam = examService.Get(result.ExamSlotId);
var examLanguage = languageService.Get(exam.LanguageId);

if (examLanguage.Language == course.Language && examLanguage.Level == course.Level)
return true;
}
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion LangLang/BusinessLogic/UseCases/LanguageLevelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public List<LanguageLevel> GetAll()
return _language.GetAll();
}

public void Add(LanguageLevel language)
public LanguageLevel Add(LanguageLevel language)
{
language.Id = GenerateId();
_language.Add(language);
return language;
}

public LanguageLevel Get(int id)
Expand Down
4 changes: 3 additions & 1 deletion LangLang/BusinessLogic/UseCases/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ public Dictionary<string, double> GetNumberOfExams()
private int GetNumberOfExams(string language)
{
var examService = new ExamSlotService();
var exams = examService.GetAll().Where(exam => exam.Language.Equals(language, StringComparison.OrdinalIgnoreCase)).ToList();
var languageService = new LanguageLevelService();

var exams = examService.GetAll().Where(exam => languageService.Get(exam.LanguageId).Language.Equals(language, StringComparison.OrdinalIgnoreCase)).ToList();
return exams.Count(exam => exam.CreatedAt >= DateTime.Now.AddYears(-1) && exam.CreatedAt <= DateTime.Now);
}

Expand Down
17 changes: 13 additions & 4 deletions LangLang/BusinessLogic/UseCases/SenderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ public void SentCoursesCreated(Director director)

private string[] GetBodyReplacements(ExamResult result, ExamSlot exam)
{
var languageService = new LanguageLevelService();
var language = languageService.Get(exam.LanguageId);

return new string[] {
exam.Language,
language.Language,
result.ReadingPoints.ToString(),
result.WritingPoints.ToString(),
result.ListeningPoints.ToString(),
Expand All @@ -176,11 +179,17 @@ private string[] GetBodyReplacements(ExamResult result, ExamSlot exam)

private string[] GetSubjectReplacements(ExamSlot exam)
{
var languageService = new LanguageLevelService();
var timeService = new TimeSlotService();

var language = languageService.Get(exam.LanguageId);
var timeSlot = timeService.Get(exam.TimeSlotId);

return new string[]
{
exam.TimeSlot.Time.ToString("dd.MM.yyyy"),
exam.Language,
exam.Level.ToString(),
timeSlot.Time.ToString("dd.MM.yyyy"),
language.Language,
language.Level.ToString()
};
}

Expand Down
7 changes: 5 additions & 2 deletions LangLang/BusinessLogic/UseCases/SmartSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ private static int GetWeightedGrade(Grade grade, int penaltiesCount, bool knowle

public static int GetTutorForExam(ExamSlot exam)
{
TutorService tutorService = new();
List<Tutor> tutors = tutorService.GetBySkill(exam.Language, exam.Level);
var tutorService = new TutorService();
var languageService = new LanguageLevelService();
var language = languageService.Get(exam.LanguageId);

List<Tutor> tutors = tutorService.GetBySkill(language.Language, language.Level);
if (tutors.Count == 0) return -1;
TutorRatingService tutorRatingService = new();
Dictionary<Tutor, double> tutorsAndRatings = new();
Expand Down
3 changes: 2 additions & 1 deletion LangLang/BusinessLogic/UseCases/TimeSlotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public TimeSlot Get(int id)
return _timeSlot.Get(id);
}

public void Add(TimeSlot timeslot)
public TimeSlot Add(TimeSlot timeslot)
{
timeslot.Id = GenerateId();
_timeSlot.Add(timeslot);
return timeslot;
}

}
Expand Down
4 changes: 2 additions & 2 deletions LangLang/Domain/Models/Course.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Course
public int Id { get; set; }
public int TutorId { get; set; }
public string Language { get; set; }
public LanguageLevel Level { get; set; }
public Level Level { get; set; }
public int NumberOfWeeks { get; set; }
public List<DayOfWeek> Days { get; set; }
public bool Online { get; set; }
Expand All @@ -27,7 +27,7 @@ public class Course


// Constructors
public Course(int id, int tutorId, string language, LanguageLevel level, int numberOfWeeks, List<DayOfWeek> days,
public Course(int id, int tutorId, string language, Level level, int numberOfWeeks, List<DayOfWeek> days,
bool online, int numberOfStudents, int maxStudents, DateTime startDateTime, bool createdByDirector, bool modifiable, bool gratitudeEmailSent, DateTime createdAt)
{
Id = id;
Expand Down
13 changes: 0 additions & 13 deletions LangLang/Domain/Models/TimeSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ public TimeSlot(int id, double duration, DateTime time)
Duration = duration;
Time = time;
}
// NOTE: Possibly redudant
//public TimeSlot(string duration, string time)
//{
// try
// {
// Time = DateTime.ParseExact(time, Constants.DATE_TIME_FORMAT, null);
// }
// catch
// {
// throw new FormatException("Date is not in the correct format.");
// }
// Duration = double.Parse(duration);
//}

public bool OverlappsWith(TimeSlot timeSlot)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void SetDataForReview()
CoursesForReview = courseService.GetAvailable(currentlyLoggedIn);
}

public void Search(string language, LanguageLevel? level, DateTime courseStartDate, int duration, bool? online)
public void Search(string language, Level? level, DateTime courseStartDate, int duration, bool? online)
{
var courseService = new CourseService();
CoursesForReview = courseService.SearchCoursesByStudent(currentlyLoggedIn, language, level, courseStartDate, duration, online);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Update()
}
}

public void Search(String language, LanguageLevel? level, DateTime courseStartDate, int duration, bool? online)
public void Search(String language, Level? level, DateTime courseStartDate, int duration, bool? online)
{
CourseService courseService = new();
CoursesForReview = courseService.SearchCoursesByTutor(LoggedIn.Id, language, level, courseStartDate, duration, !online);
Expand Down
15 changes: 7 additions & 8 deletions LangLang/WPF/ViewModels/CourseViewModels/CourseViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using LangLang.BusinessLogic.UseCases;
using LangLang.Configuration;
using LangLang.Domain.Enums;
using LangLang.Domain.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.RegularExpressions;
using LangLang.BusinessLogic.UseCases;
using LangLang.Domain.Models;
using LangLang.Domain.Enums;
using System.Reflection.Metadata;
using LangLang.Configuration;

namespace LangLang.WPF.ViewModels.CourseViewModels
{
Expand All @@ -27,7 +26,7 @@ public class CourseViewModel : INotifyPropertyChanged, IDataErrorInfo
public DateTime CreatedAt { get; set; }

private string language;
private LanguageLevel level;
private Level level;
private int numberOfWeeks;
private bool online;
private int maxStudents;
Expand Down Expand Up @@ -92,7 +91,7 @@ public DateTime StartDate
}
}

public LanguageLevel Level
public Level Level
{
get
{
Expand Down
2 changes: 1 addition & 1 deletion LangLang/WPF/ViewModels/ExamViewModels/AvailableExamsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void SendApplication()
}

}
public void SearchExams(Student loggedIn, DateTime examDate, string language, LanguageLevel? level)
public void SearchExams(Student loggedIn, DateTime examDate, string language, Level? level)
{
ExamSlotService examsService = new();
ExamsForReview = examsService.SearchByStudent(loggedIn, examDate, language, level);
Expand Down
15 changes: 10 additions & 5 deletions LangLang/WPF/ViewModels/ExamViewModels/ExamApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ExamApplicationViewModel() { }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public string Language { get; set; }
public LanguageLevel Level { get; set; }
public Level Level { get; set; }
public DateTime ExamDateTime { get; set; }


Expand All @@ -31,9 +31,14 @@ public ExamApplication ToExamApplication()
public ExamApplicationViewModel(ExamApplication application)
{
var examService = new ExamSlotService();
ExamSlot exam = examService.Get(application.ExamSlotId);
var timeService = new TimeSlotService();
var studentService = new StudentService();
var languageService = new LanguageLevelService();

ExamSlot exam = examService.Get(application.ExamSlotId);
Student student = studentService.Get(application.StudentId);
LanguageLevel language = languageService.Get(exam.LanguageId);

Id = application.Id;
ExamSlotId = application.ExamSlotId;
StudentId = application.StudentId;
Expand All @@ -44,9 +49,9 @@ public ExamApplicationViewModel(ExamApplication application)
Email = student.Profile.Email;
PhoneNumber = student.Profile.PhoneNumber;

Language = exam.Language;
Level = exam.Level;
ExamDateTime = exam.TimeSlot.Time;
Language = language.Language;
Level = language.Level;
ExamDateTime = timeService.Get(exam.TimeSlotId).Time;
}

}
Expand Down
11 changes: 6 additions & 5 deletions LangLang/WPF/ViewModels/ExamViewModels/ExamSlotCreateVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ public bool CreateExam()
}
else
{
bool added = examSlotService.Add(ExamSlot.ToExamSlot());

if (!added) MessageBox.Show("Choose another exam date or time.");
else
{
try {
examSlotService.Add(ExamSlot.ToExamSlot());
MessageBox.Show("Exam successfuly created.");
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions LangLang/WPF/ViewModels/ExamViewModels/ExamSlotSearchVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ExamSlotSearchVM(Tutor loggedIn)
examSlotsForReview = new List<ExamSlot>();
this.loggedIn = loggedIn;
ExamSlotService examsService = new();
examSlotsForReview = examsService.GetExams(loggedIn);
examSlotsForReview = examsService.GetByTutor(loggedIn);

foreach (ExamSlot exam in examSlotsForReview)
{
Expand All @@ -38,7 +38,7 @@ public void SetDataForView()
ExamSlots.Add(new ExamSlotViewModel(exam));
}
}
public void SearchExams(Tutor loggedIn,DateTime examDate,string language,LanguageLevel? level)
public void SearchExams(Tutor loggedIn, DateTime examDate, string language, Level? level)
{
ExamSlotService examsService = new();
examSlotsForReview = examsService.SearchByTutor(loggedIn, examDate, language, level);
Expand All @@ -49,7 +49,7 @@ public void SearchExams(Tutor loggedIn,DateTime examDate,string language,Languag
public void ClearExams()
{
ExamSlotService examsService = new();
examSlotsForReview = examsService.GetExams(loggedIn);
examSlotsForReview = examsService.GetByTutor(loggedIn);
SetDataForView();
}
}
Expand Down
28 changes: 20 additions & 8 deletions LangLang/WPF/ViewModels/ExamViewModels/ExamSlotViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LangLang.Configuration;
using LangLang.BusinessLogic.UseCases;
using LangLang.Configuration;
using LangLang.Domain.Enums;
using LangLang.Domain.Models;
using System;
Expand All @@ -15,7 +16,7 @@ public class ExamSlotViewModel : INotifyPropertyChanged, IDataErrorInfo

public int TutorId { get; set; }
private string language;
private LanguageLevel level;
private Level level;
private int maxStudents;
private DateTime examDate;
private string time;
Expand All @@ -37,7 +38,7 @@ public string Language
}
}

public LanguageLevel Level
public Level Level
{
get { return level; }
set
Expand Down Expand Up @@ -161,13 +162,18 @@ public ExamSlotViewModel() { }

public ExamSlotViewModel(ExamSlot examSlot)
{
var languageService = new LanguageLevelService();
var language = languageService.Get(examSlot.LanguageId);
var timeService = new TimeSlotService();
var time = timeService.Get(examSlot.TimeSlotId);

Id = examSlot.Id;
TutorId = examSlot.TutorId;
Language = examSlot.Language;
Level = examSlot.Level;
Language = language.Language;
Level = language.Level;
MaxStudents = examSlot.MaxStudents.ToString();
ExamDate = examSlot.TimeSlot.Time;
Time = examSlot.TimeSlot.Time.ToString("HH:mm");
ExamDate = time.Time;
Time = time.Time.ToString("HH:mm");
Applicants = examSlot.Applicants;
Modifiable = examSlot.Modifiable;
ResultsGenerated = examSlot.ResultsGenerated;
Expand All @@ -177,10 +183,16 @@ public ExamSlotViewModel(ExamSlot examSlot)

public ExamSlot ToExamSlot()
{
var timeService = new TimeSlotService();
string[] timeParts = time.Split(':');
int hour = int.Parse(timeParts[0]);
int minute = int.Parse(timeParts[1]);
return new ExamSlot(Id, language, level, new TimeSlot(Constants.EXAM_DURATION, new DateTime(examDate.Year, examDate.Month, examDate.Day, hour, minute, 0)), maxStudents, TutorId, applicants, Modifiable, ResultsGenerated, ExamineesNotified, CreatedAt);
// TODO: remove id
var timeSlot = new TimeSlot(0,Constants.EXAM_DURATION, new DateTime(examDate.Year, examDate.Month, examDate.Day, hour, minute, 0));
timeSlot = timeService.Add(timeSlot);
var languageService = new LanguageLevelService();
var languageLevel = languageService.Add(new LanguageLevel(0, language, level));
return new ExamSlot(Id, languageLevel.Id, timeSlot.Id, maxStudents, TutorId, applicants, Modifiable, ResultsGenerated, ExamineesNotified, CreatedAt);
}

public event PropertyChangedEventHandler? PropertyChanged;
Expand Down
Loading

0 comments on commit afe0cdd

Please sign in to comment.