Skip to content

Commit

Permalink
Merge pull request #198 from kzi-nastava/refactor/exam-slot-model
Browse files Browse the repository at this point in the history
[Refactor]: ExamSlot is independent of a specific course instance
  • Loading branch information
anasinik authored Apr 29, 2024
2 parents c3fd9d7 + 9004a44 commit 893444c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 83 deletions.
118 changes: 35 additions & 83 deletions LangLang/Core/Model/ExamSlot.cs
Original file line number Diff line number Diff line change
@@ -1,104 +1,56 @@
using LangLang.Core.Repository.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LangLang.Core.Model
{
public class ExamSlot: ISerializable
public class ExamSlot: ISerializable, Overlapable
{
// Private attributes
private int _id;
private int _courseId;
private int _maxStudents;
private DateTime _examDateTime;
private int _numberOfStudents;
public int Id { get; set; }
public string Language { get; set; }
public LanguageLevel Level { get; set; }
public int TutorId { get; set; }
public TimeSlot TimeSlot { get; set; }
public int MaxStudents { get; set; }
public bool ApplicationPossible { get; set; }

// Public properties
public int Id
{
get { return _id; }
set { _id = value; }
}

public int CourseId
{
get { return _courseId; }
set { _courseId = value; }
}

public int MaxStudents
{
get { return _maxStudents; }
set { _maxStudents = value; }
}

public DateTime ExamDateTime
{
get { return _examDateTime; }
set { _examDateTime = value; }
}
// NOTE: if possible don't save number of registeredStudents, ask the database. If not, then add attribute.


public int NumberOfStudents
public ExamSlot(int id, string language, LanguageLevel level, TimeSlot timeSlot, int maxStudents, int tutorId, bool applicationPossible)
{
get { return _numberOfStudents; }
set { _numberOfStudents = value; }
}

// Constructor
public ExamSlot(int id, int courseId, int maxStudents, DateTime examDateTime, int numberOfStudents)
{
_id = id;
_courseId = courseId;
_maxStudents = maxStudents;
_examDateTime = examDateTime;
_numberOfStudents = numberOfStudents;
}

public ExamSlot(int id, int courseId, int maxStudents, DateTime examDateTime)
{
_id = id;
_courseId = courseId;
_maxStudents = maxStudents;
_examDateTime = examDateTime;
_numberOfStudents = 0;
Id = id;
Language = language;
Level = Level;
TutorId = tutorId;
TimeSlot = timeSlot;
MaxStudents = maxStudents;
ApplicationPossible = applicationPossible;
}

public ExamSlot() { }

// Methods

// Method to display information about the exam slot
public override string ToString()
{
return $"ID: {_id} | Course: {_courseId.ToString()} | Max Students: {_maxStudents} | Exam Date and Time: {_examDateTime} | Number of Students: {_numberOfStudents}";
}

// Method to convert object to CSV format
//returns array of strings representing attributes of ExamSlot object in string form
public string[] ToCSV()
{
string[] csvValues =
{
_id.ToString(),
_courseId.ToString(),
_maxStudents.ToString(),
_examDateTime.ToString(),
_numberOfStudents.ToString()
};
return csvValues;
return new string[] {
Id.ToString(),
Language,
Level.ToString(),
TutorId.ToString(),
// TODO: add serialization for timeSlot when implemented
MaxStudents.ToString(),
ApplicationPossible.ToString()
};
}
// Method to make object from CSV data
//takes array of strings representing ExamSlot object values and sets attributes of object to that values

public void FromCSV(string[] values)
{
_id = int.Parse(values[0]);
_courseId = int.Parse(values[1]);
_maxStudents = int.Parse(values[2]);
_examDateTime = DateTime.Parse(values[3]);
_numberOfStudents = int.Parse(values[4]);
Id = int.Parse(values[0]);
Language = values[1];
Level = (LanguageLevel)Enum.Parse(typeof(LanguageLevel), values[2]);
TutorId = int.Parse(values[3]);
// TODO: add deserialization for timeSlot when implemented
MaxStudents = int.Parse(values[6]);
ApplicationPossible = bool.Parse(values[7]);
}
}
}
8 changes: 8 additions & 0 deletions LangLang/Core/Model/Overlapable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

namespace LangLang.Core.Model
{
public interface Overlapable
{
// TODO: implement
}
}
26 changes: 26 additions & 0 deletions LangLang/Core/Model/TimeSlot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Runtime.Serialization;

namespace LangLang.Core.Model
{
public class TimeSlot
{
// NOTE: Adapt as needed during implementation
public int Duration { get; set; }
public DateTime time { get; set; }

public bool OverlappsWith(TimeSlot timeSlot)
{
// TODO: Implement
return false;
}

public bool IsInFuture()
{
// TODO: Implement
return false;
}

// TODO: Add serialization methods
}
}

0 comments on commit 893444c

Please sign in to comment.