public void SubjectDistribution() { // Test creation of Scheme (containing list of: LessonDistBlock) with a Semester (containing: Dictionary<Subject, BlocksCount>, number) // Test adding block of LessonDistBlock (containing: Teacher, Subjects, BlocksCount) ClassModel aClass = new ClassModel { ClassName = "12t" }; Scheme scheme = new Scheme { ClassModel = aClass, Semester = Semester}; Assert.IsTrue(scheme.NeededSubjects().Contains(Subjects[0])); // Scheme should contain the needed subjects from the Semester Assert.IsTrue(scheme.NeededSubjects().Contains(Subjects[1])); Assert.IsTrue(scheme.NeededSubjects().Contains(Subjects[2])); Assert.IsFalse(scheme.NeededSubjects().Contains(Subjects[3])); // But not this one, because this subject is NOT in the given semester! Assert.IsTrue(scheme.AddLessonBlock(Teachers[0], Subjects[2], 30)); Assert.IsFalse(scheme.IsSubjectFull(Subjects[2], 5)); // Is the subject full if I was to try and add an additional 5? Should not be! Assert.IsTrue(scheme.IsSubjectFull(Subjects[2], 6)); // What I was to try and add 6? Should be! Assert.IsTrue(scheme.AddLessonBlock(Teachers[1], Subjects[0], 20)); Assert.IsFalse(scheme.IsSubjectFull(Subjects[1])); Assert.IsTrue(scheme.AddLessonBlock(Teachers[2], Subjects[1], 15)); Assert.IsFalse(scheme.IsSubjectFull(Subjects[1])); Assert.IsTrue(scheme.AddLessonBlock(Teachers[3], Subjects[1], 25)); Assert.IsTrue(scheme.IsSubjectFull(Subjects[1])); Assert.IsFalse(scheme.AddLessonBlock(Teachers[3], Subjects[1], 25)); // This lesson subject should be full - return false! }
/* * Dictionary<int, List<TableCellViewModel>> dic = new Dictionary<int,List<TableCellViewModel>>(); dic.Add(0, new List<TableCellViewModel>() { new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { Teacher = db.Teachers.FirstOrDefault(), SubjectName = "SD", Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } } }); dic.Add(1, new List<TableCellViewModel>() { new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, null, null, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } } }); dic.Add(2, new List<TableCellViewModel>() { new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { Teacher = db.Teachers.FirstOrDefault(), SubjectName = "SD", Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } } }); dic.Add(3, new List<TableCellViewModel>() { null, new TableCellViewModel() { Teacher = db.Teachers.FirstOrDefault(), SubjectName = "SD", Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } }, new TableCellViewModel() { SubjectName = "SD", Teacher = db.Teachers.FirstOrDefault(), Room = new Room() { RoomName = "A1.1" } } }); */ public static Dictionary<int, List<TableCellViewModel>> buildScheme(DateTime startDate, Scheme scheme) { SkeamSystemDb db = new SkeamSystemDb(); Dictionary<int, List<TableCellViewModel>> dic = new Dictionary<int, List<TableCellViewModel>>(); startDate = CalculateStartDate(startDate); DateTime endDate = startDate.AddDays(4); IEnumerable<LessonBlock> blocks = scheme.LessonBlocks.Where(l => l.Date >= startDate && l.Date <= endDate); foreach (var block in blocks) { int key = block.BlockNumber; if (dic.ContainsKey(key)) { List<TableCellViewModel> cells = dic[key]; cells[((int)block.Date.Date.DayOfWeek) - 1] = new TableCellViewModel() { BlockNumber = block.BlockNumber, Room = block.Room, SubjectName = block.Subject.Name, Teacher = block.Teacher }; dic[key] = cells; } else { List<TableCellViewModel> cells = new List<TableCellViewModel>() { null, null, null, null, null }; cells[((int)block.Date.Date.DayOfWeek) - 1] = new TableCellViewModel() { BlockNumber = block.BlockNumber, Room = block.Room, SubjectName = block.Subject.Name, Teacher = block.Teacher }; dic.Add(key, cells); } } return dic; }
public void setNewSemesterForClass(ClassModel model, Semester semester, DateTime start, DateTime finish) { Scheme scheme = new Scheme { ClassModel = model, Semester = semester, SemesterStart = start, SemesterFinish = finish }; model.ActiveSchemes.Add(scheme); }