diff --git a/LangLang/App.xaml.cs b/LangLang/App.xaml.cs index b6c2eb01..23ccfbfd 100644 --- a/LangLang/App.xaml.cs +++ b/LangLang/App.xaml.cs @@ -33,6 +33,7 @@ public App() services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/LangLang/BusinessLogic/UseCases/CourseTimeSlotService.cs b/LangLang/BusinessLogic/UseCases/CourseTimeSlotService.cs new file mode 100644 index 00000000..20c15881 --- /dev/null +++ b/LangLang/BusinessLogic/UseCases/CourseTimeSlotService.cs @@ -0,0 +1,33 @@ +using LangLang.Composition; +using LangLang.Domain.RepositoryInterfaces; +using LangLang.Domain.Models; +using System.Collections.Generic; + +namespace LangLang.BusinessLogic.UseCases +{ + public class CourseTimeSlotService + { + public ICourseTimeSlotRepository _repository; + + public CourseTimeSlotService() + { + _repository = Injector.CreateInstance(); + } + + public void Add(CourseTimeSlot courseTimeSlot) + { + _repository.Add(courseTimeSlot); + } + + public List GetAll() + { + return _repository.GetAll(); + } + + public CourseTimeSlot Get(int id) + { + return _repository.Get(id); + } + + } +} diff --git a/LangLang/BusinessLogic/UseCases/ExamSlotService.cs b/LangLang/BusinessLogic/UseCases/ExamSlotService.cs index b52eef0c..ca712ac9 100644 --- a/LangLang/BusinessLogic/UseCases/ExamSlotService.cs +++ b/LangLang/BusinessLogic/UseCases/ExamSlotService.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using LangLang.Composition; +using LangLang.Configuration; +using LangLang.Domain.Enums; using LangLang.Domain.Models; using LangLang.Domain.RepositoryInterfaces; -using LangLang.Composition; -using LangLang.Domain.Enums; -using LangLang.Configuration; - +using System; +using System.Collections.Generic; +using System.Linq; namespace LangLang.BusinessLogic.UseCases { @@ -29,11 +28,25 @@ private int GenerateId() { return _exams.Get(id); } + public List GetAll() { return _exams.GetAll(); } + public void Update(ExamSlot exam) + { + _exams.Update(exam); + } + + public void Add(ExamSlot exam) + { + if (!CanCreateExam(exam)) + throw new Exception("It's not possible to create exam, try entering different data"); + exam.Id = GenerateId(); + _exams.Add(exam); + } + public List GetGraded() { var gradedExams = new List(); @@ -51,21 +64,11 @@ public List GetGraded() // returns all graded exams for a specified language public List GetByLanguage(string language) { - var exams = GetAll().Where(exam => exam.Language.Equals(language, StringComparison.OrdinalIgnoreCase)).ToList(); var resultService = new ExamResultService(); + var languageService = new LanguageLevelService(); - return exams.Where(exam => !resultService.GetByExam(exam).All(result => result.Outcome != ExamOutcome.NotGraded && exam.ResultsGenerated)).ToList(); - } - - //function takes examslot and adds it to dictionary of examslots - //function saves changes and returns if adding was successful - public bool Add(ExamSlot exam) - { - if (!CanCreateExam(exam)) return false; - exam.Id = GenerateId(); - _exams.Add(exam); - return true; - + var exams = GetAll().Where(exam => languageService.Get(exam.LanguageId).Language.Equals(language, StringComparison.OrdinalIgnoreCase)).ToList(); + return exams.Where(exam => resultService.GetByExam(exam).All(result => result.Outcome != ExamOutcome.NotGraded && exam.ResultsGenerated)).ToList(); } public bool CanCreateExam(ExamSlot exam) @@ -77,12 +80,12 @@ public bool CanCreateExam(ExamSlot exam) public bool CoursesAndExamOverlapp(ExamSlot exam, ref int busyClassrooms) { var courseService = new CourseService(); - List courses = courseService.GetAll().ToList(); - // Go through courses - foreach (Course course in courses) + var timeService = new TimeSlotService(); + + foreach (Course course in courseService.GetAll()) { //check for overlapping - if (course.OverlappsWith(exam.TimeSlot)) + if (course.OverlappsWith(timeService.Get(exam.TimeSlotId))) { //tutor is busy (has class) if (course.TutorId == exam.TutorId) @@ -94,21 +97,22 @@ public bool CoursesAndExamOverlapp(ExamSlot exam, ref int busyClassrooms) //all classrooms are busy if (busyClassrooms == 2) return true; - } } return false; } + // Checks for any overlaps between other exams and current exam, considering the availability of the exam's tutor and classrooms public bool ExamsOverlapp(ExamSlot exam, ref int busyClassrooms) { - // Go through all exams + var timeService = new TimeSlotService(); + foreach (ExamSlot currExam in GetAll()) { if (currExam.Id == exam.Id) continue; - if (exam.TimeSlot.OverlappsWith(currExam.TimeSlot)) + if (timeService.Get(exam.TimeSlotId).OverlappsWith(timeService.Get(currExam.TimeSlotId))) { //tutor is busy (has exam) if (exam.TutorId == currExam.TutorId) @@ -125,140 +129,121 @@ public bool ExamsOverlapp(ExamSlot exam, ref int busyClassrooms) return false; } - //function takes id of examslot and removes examslot with that id - //function saves changes and returns if removing was successful - public bool Delete(int id) + public void Delete(int id) { ExamSlot exam = Get(id); - if (exam == null) return false; - if (!((exam.TimeSlot.Time - DateTime.Now).TotalDays >= Constants.EXAM_MODIFY_PERIOD)) return false; + var timeService = new TimeSlotService(); + TimeSlot timeSlot = timeService.Get(exam.TimeSlotId); + if (!((timeSlot.Time - DateTime.Now).TotalDays >= Constants.EXAM_MODIFY_PERIOD)) + throw new Exception("$Can't delete exam, there is less than {Constants.EXAM_MODIFY_PERIOD} days before exam."); + _exams.Delete(exam); - return true; - } - //deletes future exams by given tutor + public void DeleteByTutor(Tutor tutor) { - ExamApplicationService appsService = new(); - List exams = GetExams(tutor); - foreach (ExamSlot exam in exams) + var applicationService = new ExamApplicationService(); + var timeService = new TimeSlotService(); + + foreach (ExamSlot exam in GetByTutor(tutor)) { - if (exam.TimeSlot.Time > DateTime.Now) + var timeSlot = timeService.Get(exam.TimeSlotId); + + if (timeSlot.Time > DateTime.Now) { - appsService.DeleteByExam(exam); + applicationService.DeleteByExam(exam); Delete(exam.Id); } } } - public void AddStudent(ExamSlot exam) + + public void IncrementApplicants(ExamSlot exam) { exam.Applicants++; _exams.Update(exam); } - public void RemoveStudent(ExamSlot exam) + public void DecrementApplicants(ExamSlot exam) { exam.Applicants--; _exams.Update(exam); } - - public void Update(ExamSlot exam) + + public bool ApplicationsVisible(ExamSlot exam) { - _exams.Update(exam); - } + var timeSlotService = new TimeSlotService(); + TimeSlot timeSlot = timeSlotService.Get(exam.Id); + + int daysLeft = (timeSlot.Time - DateTime.Now).Days; // days left until exam + double timeLeft = (timeSlot.GetEnd() - DateTime.Now).TotalMinutes; // time left until end of exam + if (daysLeft > 0 && daysLeft < Constants.PRE_START_VIEW_PERIOD) return true; // applications become visible when there are less than PRE_START_VIEW_PERIOD days left + else if (daysLeft == 0 && timeLeft > 0) return true; // on the exam day, applications are visible until the end of exam + return false; + } + public bool CanBeUpdated(ExamSlot exam) { - return (exam.TimeSlot.Time - DateTime.Now).TotalDays >= Constants.EXAM_MODIFY_PERIOD; + var timeService = new TimeSlotService(); + return (timeService.Get(exam.TimeSlotId).Time - DateTime.Now).TotalDays >= Constants.EXAM_MODIFY_PERIOD; } - - // Method to get all exam slots by tutor ID - //function takes tutor id - public List GetExams(Tutor tutor) + public List GetByTutor(Tutor tutor) { - return _exams.GetExams(tutor); + return _exams.GetByTutor(tutor); } - - // Method to check if an exam slot is available - // takes exam slot, returns true if it is availbale or false if it isn't available public bool IsAvailable(ExamSlot exam) { - if (HasPassed(exam)) - { - return false; - } - - if (IsFullyBooked(exam)) - { - return false; - } - - if (IsLessThanMonthAway(exam)) - { + if ( HasPassed(exam) || IsFullyBooked(exam) || IsLessThanMonthAway(exam) ) return false; - } - return true; } - public bool HasPassed(ExamSlot exam) + public List SearchByTutor(Tutor tutor, DateTime examDate, string language, Level? level) { - return exam.TimeSlot.Time < DateTime.Now; + return Search(GetByTutor(tutor), examDate, language, level); } - public bool IsFullyBooked(ExamSlot exam) + public List SearchByStudent(Student student, DateTime examDate, string courseLanguage, Level? Level) { - return exam.MaxStudents == exam.Applicants; + return Search(GetAvailableExams(student), examDate, courseLanguage, Level); } - // Check if exam is less than 30 days away - private bool IsLessThanMonthAway(ExamSlot exam) + private List Search(List exams, DateTime examDate, string language, Level? level) { - DateTime currentDate = DateTime.Now; + var languageService = new LanguageLevelService(); + var timeService = new TimeSlotService(); - TimeSpan difference = exam.TimeSlot.Time - currentDate; - - return difference.TotalDays < 30; + return exams.Where(exam => (examDate == default || timeService.Get(exam.TimeSlotId).Time.Date == examDate.Date) && + (language == "" || languageService.Get(exam.LanguageId).Language == language) && + (level == null || languageService.Get(exam.LanguageId).Level == level)).ToList(); } - // Method to search exam slots by tutor and criteria - public List SearchByTutor(Tutor tutor, DateTime examDate, string language, LanguageLevel? level) - { - List exams = _exams.GetAll(); - exams = GetExams(tutor); - - return Search(exams, examDate, language, level); + public bool HasPassed(ExamSlot exam) + { + var timeService = new TimeSlotService(); + return timeService.Get(exam.TimeSlotId).Time < DateTime.Now; } - private List Search(List exams, DateTime examDate, string language, LanguageLevel? level) + public bool IsFullyBooked(ExamSlot exam) { - List filteredExams = exams.Where(exam => - (examDate == default || exam.TimeSlot.Time.Date == examDate.Date) && - (language == "" || exam.Language == language) && - (level == null || exam.Level == level) - ).ToList(); - - return filteredExams; + return exam.MaxStudents == exam.Applicants; } - - public bool ApplicationsVisible(int id) + private bool IsLessThanMonthAway(ExamSlot exam) { - ExamSlot examSlot = Get(id); - return examSlot.ApplicationsVisible(); + var timeService = new TimeSlotService(); + return (timeService.Get(exam.TimeSlotId).Time - DateTime.Now).TotalDays < 30; } - public List SearchByStudent(Student student, DateTime examDate, string courseLanguage, LanguageLevel? languageLevel) + public List GetExamsHeldInLastYear() { - List availableExamSlots = GetAvailableExams(student); - return Search(availableExamSlots, examDate, courseLanguage, languageLevel); + return GetAll().Where(exam => IsHeldInLastYear(exam)).ToList(); } - public List GetAvailableExams(Student student) { List availableExams = new(); @@ -283,9 +268,11 @@ public List GetAvailableExams(Student student) private bool HasPassedLowerLevel(List results, ExamSlot exam) { var examService = new ExamSlotService(); + var languageService = new LanguageLevelService(); + return results.Any(result => result.Outcome == ExamOutcome.Passed && - exam.Language == examService.Get(result.ExamSlotId).Language && - exam.Level < examService.Get(result.ExamSlotId).Level); + languageService.Get(exam.LanguageId).Language == languageService.Get(examService.Get(result.ExamSlotId).LanguageId).Language && + languageService.Get(exam.LanguageId).Level < languageService.Get(examService.Get(result.ExamSlotId).LanguageId).Level); } private bool HasAttendedRequiredCourse(List requests, ExamSlot exam) @@ -297,16 +284,21 @@ private bool HasAttendedRequiredCourse(List requests, ExamSlo private bool HasStudentAttendedCourse(Course course, ExamSlot examSlot) { - return course.Language == examSlot.Language && - course.Level <= examSlot.Level && - course.IsCompleted(); + var languageService = new LanguageLevelService(); + var examLanguage = languageService.Get(examSlot.LanguageId); + var courseLanguage = languageService.Get(course.LanguageLevelId); + + return courseLanguage.Language == examLanguage.Language && + courseLanguage.Level <= examLanguage.Level && course.IsCompleted(); } - public List GetExamsHeldInLastYear() + private bool IsHeldInLastYear(ExamSlot exam) { - return GetAll().Where(exam => exam.IsHeldInLastYear()).ToList(); - } + var timeService = new TimeSlotService(); + var timeSlot = timeService.Get(exam.TimeSlotId); + return timeSlot.Time > DateTime.Now.AddYears(-1); + } } } diff --git a/LangLang/BusinessLogic/UseCases/LanguageLevelService.cs b/LangLang/BusinessLogic/UseCases/LanguageLevelService.cs new file mode 100644 index 00000000..76b83b2d --- /dev/null +++ b/LangLang/BusinessLogic/UseCases/LanguageLevelService.cs @@ -0,0 +1,39 @@ +using LangLang.Composition; +using LangLang.Domain.Models; +using LangLang.Domain.RepositoryInterfaces; +using System.Collections.Generic; +using System.Linq; + +namespace LangLang.BusinessLogic.UseCases +{ + public class LanguageLevelService + { + private ILanguageLevelRepository _language; + + public LanguageLevelService() { + _language = Injector.CreateInstance(); + } + + public int GenerateId() + { + var last = GetAll().LastOrDefault(); + return last?.Id + 1 ?? 0; + } + + public List GetAll() + { + return _language.GetAll(); + } + + public void Add(LanguageLevel language) + { + language.Id = GenerateId(); + _language.Add(language); + } + + public LanguageLevel Get(int id) + { + return _language.Get(id); + } + } +} diff --git a/LangLang/BusinessLogic/UseCases/SkillService.cs b/LangLang/BusinessLogic/UseCases/SkillService.cs deleted file mode 100644 index b74f9320..00000000 --- a/LangLang/BusinessLogic/UseCases/SkillService.cs +++ /dev/null @@ -1,38 +0,0 @@ - - -using LangLang.Domain.Models; -using LangLang.Domain.RepositoryInterfaces; -using System.Collections.Generic; -using System.Linq; - -namespace LangLang.BusinessLogic.UseCases -{ - public class SkillService - { - private ISkillRepository _skills; - - public SkillService() { } - - public int GenerateId() - { - var last = GetAll().LastOrDefault(); - return last?.Id + 1 ?? 0; - } - - public List GetAll() - { - return _skills.GetAll(); - } - - public void Add(Skill skill) - { - skill.Id = GenerateId(); - _skills.Add(skill); - } - - public Skill Get(int id) - { - return _skills.Get(id); - } - } -} diff --git a/LangLang/Configuration/Injector.cs b/LangLang/Configuration/Injector.cs index 04c5e53f..aadfb63a 100644 --- a/LangLang/Configuration/Injector.cs +++ b/LangLang/Configuration/Injector.cs @@ -22,10 +22,8 @@ public static void SetServiceProvider(ServiceProvider serviceProvider) { typeof(IEnrollmentRequestRepository), new EnrollmentRequestRepository() }, { typeof(IWithdrawalRequestRepository), new WithdrawalRequestRepository() }, { typeof(ITutorRatingRepository), new TutorRatingRepository() }, - //{ typeof(IExamSlotRepository), new ExamSlotRepository() }, { typeof(IExamApplicationRepository), new ExamApplicationRepository() }, { typeof(IPenaltyPointRepository), new PenaltyPointRepository() }, - //{ typeof(ICourseRepository), new CourseRepository() }, { typeof(IGradeRepository), new GradeRepository() }, { typeof(IExamResultRepository), new ExamResultRepository() }, { typeof(IEmailRepository), new EmailRepository() } diff --git a/LangLang/Data/examSlots.csv b/LangLang/Data/examSlots.csv deleted file mode 100644 index 83f70cd9..00000000 --- a/LangLang/Data/examSlots.csv +++ /dev/null @@ -1,2 +0,0 @@ -0|Serbian|C1|0|4|2024-05-27 17:00|10|1|True|False|False|2024-03-05 17:00 -1|Serbian|B1|0|4|2024-07-02 14:00|5|0|True|False|False|2024-03-06 20:45 diff --git a/LangLang/Domain/Enums/LanguageLevel.cs b/LangLang/Domain/Enums/LanguageLevel.cs deleted file mode 100644 index 984497ee..00000000 --- a/LangLang/Domain/Enums/LanguageLevel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LangLang.Domain.Enums -{ - public enum LanguageLevel - { - A1, - A2, - B1, - B2, - C1, - C2 - } -} diff --git a/LangLang/Domain/Enums/Level.cs b/LangLang/Domain/Enums/Level.cs new file mode 100644 index 00000000..974bef3e --- /dev/null +++ b/LangLang/Domain/Enums/Level.cs @@ -0,0 +1,12 @@ +namespace LangLang.Domain.Enums +{ + public enum Level + { + A1, + A2, + B1, + B2, + C1, + C2 + } +} diff --git a/LangLang/Domain/Models/CourseTimeSlot.cs b/LangLang/Domain/Models/CourseTimeSlot.cs new file mode 100644 index 00000000..97f4cfd5 --- /dev/null +++ b/LangLang/Domain/Models/CourseTimeSlot.cs @@ -0,0 +1,17 @@ +namespace LangLang.Domain.Models +{ + public class CourseTimeSlot + { + public int Id { get; set; } + public int CourseId { get; set; } + public int TimeSlotId { get; set; } + + public CourseTimeSlot(int id, int courseId, int timeSlotId) + { + Id = id; + CourseId = courseId; + TimeSlotId = timeSlotId; + } + + } +} diff --git a/LangLang/Domain/Models/ExamSlot.cs b/LangLang/Domain/Models/ExamSlot.cs index 64ca0f91..72f2ebdc 100644 --- a/LangLang/Domain/Models/ExamSlot.cs +++ b/LangLang/Domain/Models/ExamSlot.cs @@ -1,16 +1,13 @@ -using LangLang.Configuration; -using LangLang.Domain.Enums; -using System; +using System; namespace LangLang.Domain.Models { public class ExamSlot { public int Id { get; set; } - public string Language { get; set; } - public LanguageLevel Level { get; set; } + public int LanguageId { get; set; } public int TutorId { get; set; } - public TimeSlot TimeSlot { get; set; } + public int TimeSlotId { get; set; } public int MaxStudents { get; set; } public int Applicants { get; set; } public bool Modifiable { get; set; } @@ -18,13 +15,12 @@ public class ExamSlot public bool ExamineesNotified { get; set; } public DateTime CreatedAt { get; set; } - public ExamSlot(int id, string language, LanguageLevel level, TimeSlot timeSlot, int maxStudents, int tutorId, int applicants, bool modifiable, bool generatedResults, bool examineesNotified, DateTime createdAt) + public ExamSlot(int id, int languageId, int timeSlotId, int maxStudents, int tutorId, int applicants, bool modifiable, bool generatedResults, bool examineesNotified, DateTime createdAt) { Id = id; - Language = language; - Level = level; + LanguageId = languageId; TutorId = tutorId; - TimeSlot = timeSlot; + TimeSlotId = timeSlotId; MaxStudents = maxStudents; Applicants = applicants; Modifiable = modifiable; @@ -35,19 +31,5 @@ public ExamSlot(int id, string language, LanguageLevel level, TimeSlot timeSlot, public ExamSlot() { } - public bool ApplicationsVisible() - { - int daysLeft = (TimeSlot.Time - DateTime.Now).Days; // days left until exam - double timeLeft = (TimeSlot.GetEnd() - DateTime.Now).TotalMinutes; // time left until end of exam - - if (daysLeft > 0 && daysLeft < Constants.PRE_START_VIEW_PERIOD) return true; // applications become visible when there are less than PRE_START_VIEW_PERIOD days left - else if (daysLeft == 0 && timeLeft > 0) return true; // on the exam day, applications are visible until the end of exam - return false; - } - public bool IsHeldInLastYear() - { - DateTime oneYearAgo = DateTime.Now.AddYears(-1); - return TimeSlot.Time > oneYearAgo; - } } } diff --git a/LangLang/Domain/Models/Skill.cs b/LangLang/Domain/Models/LanguageLevel.cs similarity index 51% rename from LangLang/Domain/Models/Skill.cs rename to LangLang/Domain/Models/LanguageLevel.cs index 8b8a78fa..2afac19f 100644 --- a/LangLang/Domain/Models/Skill.cs +++ b/LangLang/Domain/Models/LanguageLevel.cs @@ -1,17 +1,16 @@ -using System.Collections.Generic; -using LangLang.Domain.Enums; +using LangLang.Domain.Enums; namespace LangLang.Domain.Models { - public class Skill + public class LanguageLevel { public int Id { get; set; } public string Language { get; set; } - public LanguageLevel Level { get; set; } + public Level Level { get; set; } - public Skill() {} + public LanguageLevel() {} - public Skill(int id, string language, LanguageLevel level) + public LanguageLevel(int id, string language, Level level) { Id = id; Language = language; diff --git a/LangLang/Domain/Models/TimeSlot.cs b/LangLang/Domain/Models/TimeSlot.cs index 427407f2..b3d34a74 100644 --- a/LangLang/Domain/Models/TimeSlot.cs +++ b/LangLang/Domain/Models/TimeSlot.cs @@ -1,5 +1,4 @@ using System; -using LangLang.Configuration; namespace LangLang.Domain.Models { @@ -9,26 +8,25 @@ public class TimeSlot public double Duration { get; set; } public DateTime Time { get; set; } - public TimeSlot(double duration, DateTime time) + public TimeSlot(int id, double duration, DateTime time) { - + Id = id; Duration = duration; Time = time; } - - 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); - - } + // 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) { @@ -43,11 +41,6 @@ public bool IsInFuture() return Time > DateTime.Now; } - public string ToString() - { - return Duration.ToString() + '|' + Time.ToString(Constants.DATE_TIME_FORMAT); - } - public DateTime GetEnd() { return Time.AddHours(Duration); diff --git a/LangLang/Domain/RepositoryInterfaces/ICourseTimeSlotRepository.cs b/LangLang/Domain/RepositoryInterfaces/ICourseTimeSlotRepository.cs new file mode 100644 index 00000000..64dd9336 --- /dev/null +++ b/LangLang/Domain/RepositoryInterfaces/ICourseTimeSlotRepository.cs @@ -0,0 +1,12 @@ +using LangLang.Domain.Models; +using System.Collections.Generic; + +namespace LangLang.Domain.RepositoryInterfaces +{ + public interface ICourseTimeSlotRepository + { + public List GetAll(); + public CourseTimeSlot Get(int id); + public void Add(CourseTimeSlot courseTimeSlot); + } +} diff --git a/LangLang/Domain/RepositoryInterfaces/IExamSlotRepository.cs b/LangLang/Domain/RepositoryInterfaces/IExamSlotRepository.cs index db87c362..1c3b6c27 100644 --- a/LangLang/Domain/RepositoryInterfaces/IExamSlotRepository.cs +++ b/LangLang/Domain/RepositoryInterfaces/IExamSlotRepository.cs @@ -7,7 +7,7 @@ public interface IExamSlotRepository { public List GetAll(); public ExamSlot Get(int id); - public List GetExams(Tutor tutor); + public List GetByTutor(Tutor tutor); public void Add(ExamSlot exam); public void Delete(ExamSlot exam); public void Update(ExamSlot exam); diff --git a/LangLang/Domain/RepositoryInterfaces/ILanguageLevelRepository.cs b/LangLang/Domain/RepositoryInterfaces/ILanguageLevelRepository.cs new file mode 100644 index 00000000..7a908a0d --- /dev/null +++ b/LangLang/Domain/RepositoryInterfaces/ILanguageLevelRepository.cs @@ -0,0 +1,12 @@ +using LangLang.Domain.Models; +using System.Collections.Generic; + +namespace LangLang.Domain.RepositoryInterfaces +{ + public interface ILanguageLevelRepository + { + public List GetAll(); + public LanguageLevel Get(int id); + public void Add(LanguageLevel language); + } +} diff --git a/LangLang/Domain/RepositoryInterfaces/ISkillRepository.cs b/LangLang/Domain/RepositoryInterfaces/ISkillRepository.cs deleted file mode 100644 index d09e9270..00000000 --- a/LangLang/Domain/RepositoryInterfaces/ISkillRepository.cs +++ /dev/null @@ -1,16 +0,0 @@ -using LangLang.Domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LangLang.Domain.RepositoryInterfaces -{ - public interface ISkillRepository - { - public List GetAll(); - public Skill Get(int id); - public void Add(Skill skill); - } -} diff --git a/LangLang/Repositories/CourseTimeSlotRepository.cs b/LangLang/Repositories/CourseTimeSlotRepository.cs new file mode 100644 index 00000000..4d067232 --- /dev/null +++ b/LangLang/Repositories/CourseTimeSlotRepository.cs @@ -0,0 +1,34 @@ +using LangLang.Domain.Models; +using LangLang.Domain.RepositoryInterfaces; +using System.Collections.Generic; +using System.Linq; + +namespace LangLang.Repositories +{ + public class CourseTimeSlotRepository : ICourseTimeSlotRepository + { + public DatabaseContext _context; + + public CourseTimeSlotRepository(DatabaseContext context) + { + _context = context; + } + + public void Add(CourseTimeSlot courseTimeSlot) + { + _context.CourseTimeSlot.Add(courseTimeSlot); + _context.SaveChanges(); + } + + public CourseTimeSlot Get(int id) + { + return _context.CourseTimeSlot.Find(id); + } + + public List GetAll() + { + return _context.CourseTimeSlot.ToList(); + } + + } +} diff --git a/LangLang/Repositories/DatabaseContext.cs b/LangLang/Repositories/DatabaseContext.cs index 4be10151..d24916e2 100644 --- a/LangLang/Repositories/DatabaseContext.cs +++ b/LangLang/Repositories/DatabaseContext.cs @@ -12,11 +12,13 @@ public DatabaseContext(DbContextOptions options) : base(options public DbSet Course { get; set; } public DbSet ExamSlot { get; set; } public DbSet LanguageLevel { get; set; } + public DbSet CourseTimeSlot { get; set; } public DbSet TutorSkill { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { + base.OnModelCreating(modelBuilder); ConfigureTutorEntity(modelBuilder); modelBuilder.Entity().ToTable("Tutor"); @@ -24,6 +26,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity().ToTable("ExamSlot"); modelBuilder.Entity().ToTable("TimeSlot"); modelBuilder.Entity().ToTable("LanguageLevel"); + modelBuilder.Entity().ToTable("CourseTimeSlot"); modelBuilder.Entity().ToTable("TutorSkill"); } @@ -45,7 +48,6 @@ private void ConfigureTutorEntity(ModelBuilder modelBuilder) profile.Property(p => p.Role).HasColumnName("Role"); profile.Property(p => p.IsActive).HasColumnName("IsActive"); }); - } } } \ No newline at end of file diff --git a/LangLang/Repositories/ExamSlotRepository.cs b/LangLang/Repositories/ExamSlotRepository.cs index 82373529..6d72548d 100644 --- a/LangLang/Repositories/ExamSlotRepository.cs +++ b/LangLang/Repositories/ExamSlotRepository.cs @@ -1,6 +1,5 @@ using LangLang.Domain.Models; using LangLang.Domain.RepositoryInterfaces; -using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; @@ -8,45 +7,44 @@ namespace LangLang.Repositories { public class ExamSlotRepository : IExamSlotRepository { - private readonly DatabaseContext _databaseContext; + private readonly DatabaseContext _context; public ExamSlotRepository(DatabaseContext context) { - _databaseContext = context; + _context = context; } public ExamSlot? Get(int id) { - return _databaseContext.ExamSlot.Find(id); + return _context.ExamSlot.Find(id); } public List GetAll() { - return _databaseContext.ExamSlot.ToList(); + return _context.ExamSlot.ToList(); } - public List GetExams(Tutor tutor) + public List GetByTutor(Tutor tutor) { - return _databaseContext.ExamSlot.Where(es => es.TutorId == tutor.Id).ToList(); + return _context.ExamSlot.Where(es => es.TutorId == tutor.Id).ToList(); } public void Add(ExamSlot exam) { - _databaseContext.ExamSlot.Add(exam); - _databaseContext.SaveChanges(); - + _context.ExamSlot.Add(exam); + _context.SaveChanges(); } public void Update(ExamSlot exam) { - _databaseContext.ExamSlot.Update(exam); - _databaseContext.SaveChanges(); + _context.ExamSlot.Update(exam); + _context.SaveChanges(); } public void Delete(ExamSlot exam) { - _databaseContext.ExamSlot.Remove(exam); - _databaseContext.SaveChanges(); + _context.ExamSlot.Remove(exam); + _context.SaveChanges(); } } } \ No newline at end of file diff --git a/LangLang/Repositories/LanguageLevelRepository.cs b/LangLang/Repositories/LanguageLevelRepository.cs new file mode 100644 index 00000000..8f9988a0 --- /dev/null +++ b/LangLang/Repositories/LanguageLevelRepository.cs @@ -0,0 +1,32 @@ +using LangLang.Domain.Models; +using LangLang.Domain.RepositoryInterfaces; +using System.Collections.Generic; +using System.Linq; + +namespace LangLang.Repositories +{ + public class LanguageLevelRepository : ILanguageLevelRepository + { + private readonly DatabaseContext _context; + + public LanguageLevelRepository(DatabaseContext context) + { + _context = context; + } + public void Add(LanguageLevel language) + { + _context.LanguageLevel.Add(language); + _context.SaveChanges(); + } + + public LanguageLevel Get(int id) + { + return _context.LanguageLevel.Find(id); + } + + public List GetAll() + { + return _context.LanguageLevel.ToList(); + } + } +} diff --git a/LangLang/Repositories/SkillRepository.cs b/LangLang/Repositories/SkillRepository.cs deleted file mode 100644 index e7df9ee9..00000000 --- a/LangLang/Repositories/SkillRepository.cs +++ /dev/null @@ -1,33 +0,0 @@ - -using LangLang.Domain.Models; -using LangLang.Domain.RepositoryInterfaces; -using System.Collections.Generic; -using System.Linq; - -namespace LangLang.Repositories -{ - public class SkillRepository : ISkillRepository - { - private readonly DatabaseContext _databaseContext; - - public SkillRepository(DatabaseContext context) - { - _databaseContext = context; - } - public void Add(Skill skill) - { - _databaseContext.Skill.Add(skill); - _databaseContext.SaveChanges(); - } - - public Skill Get(int id) - { - return _databaseContext.Skill.Find(id); - } - - public List GetAll() - { - return _databaseContext.Skill.ToList(); - } - } -}