public int AddCurriculumChapter(CurriculumChapter curriculumChapter) { var db = GetDbContext(); curriculumChapter.IsDeleted = false; db.CurriculumChapters.InsertOnSubmit(curriculumChapter); db.SubmitChanges(); //add corresponding curriculum chapter topics var topics = GetTopicsByChapterId(curriculumChapter.ChapterRef); foreach (var topic in topics) { var curriculumChapterTopic = new CurriculumChapterTopic { CurriculumChapterRef = curriculumChapter.Id, TopicRef = topic.Id, MaxScore = Constants.DefaultTopicMaxScore, BlockTopicAtTesting = false, BlockCurriculumAtTesting = false }; AddCurriculumChapterTopic(curriculumChapterTopic); } return(curriculumChapter.Id); }
public int AddChapter(Chapter chapter) { var db = GetDbContext(); chapter.Created = DateTime.Now; chapter.Updated = DateTime.Now; chapter.IsDeleted = false; db.Chapters.InsertOnSubmit(chapter); db.SubmitChanges(); //add corresponding CurriculumChapters var curriculums = GetCurriculumsByDisciplineId(chapter.DisciplineRef); foreach (var curriculum in curriculums) { var curriculumChapter = new CurriculumChapter { ChapterRef = chapter.Id, CurriculumRef = curriculum.Id }; AddCurriculumChapter(curriculumChapter); } return(chapter.Id); }
public int AddCurriculum(Curriculum curriculum) { var db = GetDbContext(); curriculum.IsDeleted = false; curriculum.IsValid = true; db.Curriculums.InsertOnSubmit(curriculum); db.SubmitChanges(); //add corresponding curriculum chapters var chapters = GetChapters(curriculum.DisciplineRef); foreach (var chapter in chapters) { var curriculumChapter = new CurriculumChapter { ChapterRef = chapter.Id, CurriculumRef = curriculum.Id }; AddCurriculumChapter(curriculumChapter); } return(curriculum.Id); }
public void UpdateCurriculumChapter(CurriculumChapter curriculumChapter) { this.storage.UpdateCurriculumChapter(curriculumChapter); this.cacheProvider.Invalidate("curriculumchapter-" + curriculumChapter.Id, "curriculumchapters"); this.cacheProvider.Invalidate("curriculums", "curriculum-" + curriculumChapter.CurriculumRef); }
/// <summary> /// Validates the curriculum chapter. /// </summary> /// <param name="data">The curriculum chapter.</param> /// <returns></returns> public ValidationStatus ValidateCurriculumChapter(CurriculumChapter data) { var validationStatus = new ValidationStatus(); ValidateDate(data.StartDate, data.EndDate, validationStatus); return(validationStatus); }
public int AddCurriculumChapter(CurriculumChapter curriculumChapter) { var id = this.storage.AddCurriculumChapter(curriculumChapter); this.cacheProvider.Invalidate("curriculumchapter-" + id, "curriculumchapters"); this.cacheProvider.Invalidate("curriculums", "curriculum-" + curriculumChapter.CurriculumRef); return(id); }
/// <summary> /// Validates the curriculum chapter. /// </summary> /// <param name="data">The curriculum chapter.</param> /// <returns></returns> public ValidationStatus ValidateCurriculumChapter(CurriculumChapter data) { ValidationStatus validationStatus = new ValidationStatus(); ValidateDate(data.StartDate, data.EndDate, validationStatus); //TODO: check topic timelines and curriculum timelines! return(validationStatus); }
public void UpdateCurriculumChapter(CurriculumChapter curriculumChapter) { var db = GetDbContext(); var oldCurriculumChapter = GetCurriculumChapter(db, curriculumChapter.Id); oldCurriculumChapter.StartDate = curriculumChapter.StartDate; oldCurriculumChapter.EndDate = curriculumChapter.EndDate; db.SubmitChanges(); }
public void UpdateCurriculumChapter(CurriculumChapter curriculumChapter) { var db = this.GetDbContext(); var oldCurriculumChapter = GetCurriculumChapter(db, curriculumChapter.Id); oldCurriculumChapter.StartDate = curriculumChapter.StartDate; oldCurriculumChapter.EndDate = curriculumChapter.EndDate; db.SubmitChanges(); var curriculum = GetCurriculum(db, oldCurriculumChapter.CurriculumRef); curriculum.IsValid = this.IsCurriculumValid(curriculum); db.SubmitChanges(); }
public int AddCurriculumChapter(CurriculumChapter curriculumChapter) { var db = this.GetDbContext(); curriculumChapter.IsDeleted = false; db.CurriculumChapters.InsertOnSubmit(curriculumChapter); var curriculum = GetCurriculum(db, curriculumChapter.CurriculumRef); if (curriculumChapter.StartDate < curriculum.StartDate || curriculumChapter.EndDate > curriculum.EndDate) { curriculum.IsValid = false; } db.SubmitChanges(); // add corresponding curriculum chapter topics var topics = this.GetTopicsByChapterId(curriculumChapter.ChapterRef); foreach (var topic in topics) { var curriculumChapterTopic = new CurriculumChapterTopic { CurriculumChapterRef = curriculumChapter.Id, TopicRef = topic.Id, ThresholdOfSuccess = Constants.DefaultThresholdOfSuccess, BlockTopicAtTesting = false, BlockCurriculumAtTesting = false }; this.AddCurriculumChapterTopic(curriculumChapterTopic); } return(curriculumChapter.Id); }
public static CreateCurriculumChapterModel ToCreateModel(this CurriculumChapter curriculumChapter) { return(new CreateCurriculumChapterModel(curriculumChapter.StartDate, curriculumChapter.EndDate)); }
public void AddCurriculum() { this.DataPreparer.CreateCurriculumsSet1(); var expectedItems = this.DataPreparer.GetCurriculums(); var controller = this.GetController <CurriculumController>(); // add curriculums expectedItems.ForEach(item => controller.Create(item.ToCreateModel())); // then add "special" curriculum controller.Create( new Curriculum { IsValid = false, IsDeleted = true, DisciplineRef = this.DataPreparer.DisciplineIds[0], UserGroupRef = this.UserService.GetGroup(2).Id }.ToCreateModel()); expectedItems = this.DataPreparer.GetCurriculums(); var allItems = this.CurriculumStorage.GetCurriculums().OrderBy(item => item.Id).ToList(); var actualItems = allItems.Take(expectedItems.Count).ToList(); var actualItem = allItems.Last(); Assert.AreEqual(expectedItems.Count, actualItems.Count); Assert.AreEqual(true, actualItem.IsValid); Assert.AreEqual(false, actualItem.IsDeleted); // add bad curriculum controller = this.GetController <CurriculumController>(); controller.Create( new Curriculum { DisciplineRef = this.DataPreparer.DisciplineIds[1], UserGroupRef = this.UserService.GetGroup(1).Id, StartDate = DateTime.Now.AddDays(1), // bad start date EndDate = DateTime.Now }.ToCreateModel()); Assert.AreEqual(false, controller.ModelState.IsValid); Assert.AreEqual(expectedItems.Count + 1, this.CurriculumStorage.GetCurriculums().Count); // add bad curriculum controller = this.GetController <CurriculumController>(); controller.Create( new Curriculum { DisciplineRef = this.DataPreparer.DisciplineIds[0], // curriculum with same group and discipline already exist! UserGroupRef = this.UserService.GetGroup(2).Id, StartDate = DateTime.Now, EndDate = DateTime.Now }.ToCreateModel()); Assert.AreEqual(false, controller.ModelState.IsValid); Assert.AreEqual(expectedItems.Count + 1, this.CurriculumStorage.GetCurriculums().Count); // add bad curriculum controller = this.GetController <CurriculumController>(); controller.Create( new Curriculum { DisciplineRef = -1, // disciplineId < 0 UserGroupRef = this.UserService.GetGroup(2).Id, StartDate = DateTime.Now, EndDate = DateTime.Now }.ToCreateModel()); Assert.AreEqual(false, controller.ModelState.IsValid); Assert.AreEqual(expectedItems.Count + 1, this.CurriculumStorage.GetCurriculums().Count); // add bad curriculum controller = this.GetController <CurriculumController>(); controller.Create( new Curriculum { DisciplineRef = this.DataPreparer.DisciplineIds[0], UserGroupRef = -1, // groupId < 0 StartDate = DateTime.Now, EndDate = DateTime.Now }.ToCreateModel()); Assert.AreEqual(false, controller.ModelState.IsValid); Assert.AreEqual(expectedItems.Count + 1, this.CurriculumStorage.GetCurriculums().Count); // add bad curriculum controller = this.GetController <CurriculumController>(); controller.Create( new Curriculum { DisciplineRef = this.DataPreparer.DisciplineIds[1], UserGroupRef = this.UserService.GetGroup(1).Id, StartDate = new DateTime(1100, 1, 1), // too small date EndDate = new DateTime(2400, 1, 1) // too big date }.ToCreateModel()); Assert.AreEqual(false, controller.ModelState.IsValid); Assert.AreEqual(expectedItems.Count + 1, this.CurriculumStorage.GetCurriculums().Count); var curriculum = new Curriculum { DisciplineRef = this.DataPreparer.DisciplineIds[0], UserGroupRef = this.UserService.GetGroup(1).Id, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2) }; var curriculumId = this.CurriculumStorage.AddCurriculum(curriculum); var discipline = this.DisciplineStorage.GetDiscipline(this.DataPreparer.DisciplineIds[0]); var chapterId = this.DisciplineStorage.GetChapters(item => item.DisciplineRef == discipline.Id).First().Id; var curriculumChapter = new CurriculumChapter() { ChapterRef = chapterId, CurriculumRef = curriculumId, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(4) }; this.CurriculumStorage.AddCurriculumChapter(curriculumChapter); curriculum = this.CurriculumStorage.GetCurriculum(curriculumId); Assert.IsFalse(curriculum.IsValid); }
public string ImportCourse(ScheduleCourse scheduleCourse) { string msg; _Logger.DebugFormat("Importiere Fach: {0}", scheduleCourse.Name); _report.AppendFormat("<h1>Erzeuge LV \"{0} ({1})\" - [{2}]</h1>", scheduleCourse.Name, scheduleCourse.ShortName, scheduleCourse.CourseId); _report.AppendLine(); var db = new TimeTableDbContext(); var organiser = db.Organisers.SingleOrDefault(s => s.Id == _orgId); var sem = db.Semesters.SingleOrDefault(s => s.Id == _semId); long msStart = sw.ElapsedMilliseconds; var course = new Course { ExternalSource = "JSON", ExternalId = scheduleCourse.CourseId, Organiser = organiser, ShortName = scheduleCourse.ShortName, Name = scheduleCourse.Name, Description = scheduleCourse.Description, Occurrence = CreateDefaultOccurrence(scheduleCourse.SeatRestriction ?? 0), IsInternal = true, }; // Kurs sofort speichern, damit die ID gesichert ist db.Activities.Add(course); db.SaveChanges(); long msEnd = sw.ElapsedMilliseconds; _Logger.DebugFormat("Dauer: {0}ms", msEnd - msStart); msStart = msEnd; _report.AppendLine("<h2>Bezeichnungen</h2>"); _report.AppendLine("<table>"); _report.AppendFormat("<tr><td>Name</td><td>{0}</td></tr>", course.Name); _report.AppendFormat("<tr><td>Kurzname</td><td>{0}</td></tr>", course.ShortName); _report.AppendFormat("<tr><td>Beschreibung</td><td>{0}</td></tr>", course.Description); _report.AppendLine("</table>"); // jetzt die Gruppen foreach (var scheduleGroup in scheduleCourse.Groups) { // Fakultät ermitteln var org = db.Organisers.SingleOrDefault(x => x.ShortName.Equals(scheduleGroup.FacultyName)); // Studiengang innerhalb der Fakultät ermitteln var curr = org.Curricula.SingleOrDefault(x => x.ShortName.Equals(scheduleGroup.CurriculumShortName)); if (curr == null) { curr = new TimeTable.Data.Curriculum { ShortName = scheduleGroup.CurriculumShortName, Name = scheduleGroup.CurriculumName, Organiser = org }; db.Curricula.Add(curr); db.SaveChanges(); } // Studiengruppe innerhalb des Studiengangs ermitteln var groupName = scheduleGroup.GroupName; // Sonderlocke FK 11 // aus der LV-Nummer das Semester raussuchen /* OHI 20180720: wieder ausgebaut, weil Schnittstelle jetzt sauber befüllt ist * if (org.ShortName.Equals("FK 11")) * { * if (!string.IsNullOrEmpty(course.ShortName)) * { * groupName = course.ShortName[1].ToString(); * * } * else * { * groupName = "#N.V."; * } * } */ var currGroup = curr.CurriculumGroups.SingleOrDefault(x => x.Name.Equals(groupName)); if (currGroup == null) { currGroup = new CurriculumGroup { Curriculum = curr, Name = groupName, IsSubscribable = true, }; db.CurriculumGroups.Add(currGroup); db.SaveChanges(); } // Kapazitätsgruppe innerhalb der Studiengruppe ermitteln CapacityGroup capGroup = null; if (string.IsNullOrEmpty(scheduleGroup.SubGroupName)) { capGroup = currGroup.CapacityGroups.SingleOrDefault(x => string.IsNullOrEmpty(x.Name)); if (capGroup == null) { capGroup = new CapacityGroup { CurriculumGroup = currGroup, Name = string.Empty, InSS = scheduleGroup.SemesterName.StartsWith("SS"), InWS = scheduleGroup.SemesterName.StartsWith("WS") }; db.CapacityGroups.Add(capGroup); db.SaveChanges(); } } else { capGroup = currGroup.CapacityGroups.SingleOrDefault(x => !string.IsNullOrEmpty(x.Name) && x.Name.Equals(scheduleGroup.SubGroupName)); if (capGroup == null) { capGroup = new CapacityGroup { CurriculumGroup = currGroup, Name = scheduleGroup.SubGroupName, InSS = scheduleGroup.SemesterName.StartsWith("SS"), InWS = scheduleGroup.SemesterName.StartsWith("WS") }; db.CapacityGroups.Add(capGroup); db.SaveChanges(); } } // Semester ermitteln var semester = db.Semesters.SingleOrDefault(x => x.Name.Equals(scheduleGroup.SemesterName)); if (semester.Id == sem.Id) { // jetzt können wir die Semestergruppe ermitteln var semGroup = db.SemesterGroups.SingleOrDefault(x => x.Semester.Id == semester.Id && x.CapacityGroup.Id == capGroup.Id); if (semGroup == null) { semGroup = new SemesterGroup { Semester = semester, CapacityGroup = capGroup, IsAvailable = false // zu Beginn nicht freigegeben }; db.SemesterGroups.Add(semGroup); db.SaveChanges(); } course.SemesterGroups.Add(semGroup); semGroup.Activities.Add(course); // zu jeder Semestergruppe gibt es dann noch eine // Gruppe für Platzverlosung var occGroup = course.Occurrence.Groups.SingleOrDefault( gg => gg.SemesterGroups.Any(s => s.Id == semGroup.Id)); if (occGroup == null) { occGroup = new OccurrenceGroup { Capacity = 0, FitToCurriculumOnly = true, Occurrence = course.Occurrence }; occGroup.SemesterGroups.Add(semGroup); semGroup.OccurrenceGroups.Add(occGroup); course.Occurrence.Groups.Add(occGroup); db.OccurrenceGroups.Add(occGroup); } // NEU: Chapter und Topics if (!string.IsNullOrEmpty(scheduleGroup.ChapterName) && !string.IsNullOrEmpty(scheduleGroup.TopicName)) { var chapter = curr.Chapters.FirstOrDefault(x => x.Name.Equals(scheduleGroup.ChapterName)); if (chapter == null) { chapter = new CurriculumChapter { Curriculum = curr, Name = scheduleGroup.ChapterName }; db.CurriculumChapters.Add(chapter); } var topic = chapter.Topics.FirstOrDefault(x => x.Name.Equals(scheduleGroup.TopicName)); if (topic == null) { topic = new CurriculumTopic { Chapter = chapter, Name = scheduleGroup.TopicName }; db.CurriculumTopics.Add(topic); } var semTopic = db.SemesterTopics.FirstOrDefault(x => x.Semester.Id == sem.Id && x.Topic.Id == topic.Id); if (semTopic == null) { semTopic = new SemesterTopic { Semester = sem, Topic = topic, }; db.SemesterTopics.Add(semTopic); } semTopic.Activities.Add(course); } } // else => Semestergruppe wird nicht angelegt } db.SaveChanges(); if (!course.SemesterGroups.Any()) { _Logger.ErrorFormat("Kurs {0} ohne Gruppe", scheduleCourse.CourseId); } // zum Schluss die Termine _report.AppendLine("<h2>Neue Termine</h2>"); _report.AppendLine("<table>"); foreach (var scheduleDate in scheduleCourse.Dates) { // Der Tag var occDate = scheduleDate.Begin.Date; bool isVorlesung = true; foreach (var sd in _semester.Dates) { // Wenn der Termin in eine vorlesungsfreie Zeit fällt, dann nicht importieren if (sd.From.Date <= occDate.Date && occDate.Date <= sd.To.Date && sd.HasCourses == false) { isVorlesung = false; } } if (isVorlesung) { var occ = new ActivityDate { Begin = scheduleDate.Begin, End = scheduleDate.End, Activity = course, Occurrence = CreateDefaultOccurrence(), }; _report.AppendLine("<tr>"); _report.AppendFormat("<td>{0}</td><td>{1}</td><td>{2}</td>", occ.Begin.ToShortDateString(), occ.Begin.ToShortTimeString(), occ.End.ToShortTimeString()); _report.AppendFormat("<td>"); foreach (var scheduleDateRoom in scheduleDate.Rooms) { _report.AppendFormat("<p>{0}", scheduleDateRoom.RoomNumber); if (!string.IsNullOrEmpty(scheduleDateRoom.RoomNumber)) { var room = db.Rooms.SingleOrDefault(r => r.Number.Equals(scheduleDateRoom.RoomNumber)); if (room == null) { room = new Room { Number = scheduleDateRoom.RoomNumber, Capacity = 0, Description = string.Empty, Owner = string.Empty, }; db.Rooms.Add(room); db.SaveChanges(); _numRooms++; _report.AppendFormat(" !!!NEUER RAUM!!!"); } var assignment = db.RoomAssignments.SingleOrDefault(x => x.Room.Id == room.Id && x.Organiser.Id == organiser.Id); if (assignment == null) { assignment = new RoomAssignment { Organiser = organiser, InternalNeedConfirmation = false, // offen für interne ExternalNeedConfirmation = true // geschlossen für externe }; room.Assignments.Add(assignment); db.RoomAssignments.Add(assignment); db.SaveChanges(); } occ.Rooms.Add(room); _report.AppendFormat("</p>"); } } _report.AppendFormat("</td>"); _report.AppendFormat("<td>"); foreach (var scheduleDateLecturer in scheduleDate.Lecturers) { _report.AppendFormat("<p>{0} ({1})", scheduleDateLecturer.Name, scheduleDateLecturer.ShortName); var lecturer = organiser.Members.SingleOrDefault(l => l.ShortName.Equals(scheduleDateLecturer.ShortName)); if (lecturer == null) { lecturer = new OrganiserMember { ShortName = scheduleDateLecturer.ShortName, Name = scheduleDateLecturer.Name, Role = String.Empty, Description = String.Empty }; organiser.Members.Add(lecturer); db.Members.Add(lecturer); db.SaveChanges(); _numLecturers++; _report.AppendFormat(" !!!NEUER DOZENT!!!"); } occ.Hosts.Add(lecturer); _report.AppendFormat("</p>"); } _report.AppendFormat("</td>"); db.ActivityDates.Add(occ); _report.AppendLine(); _report.AppendLine("</tr>"); } } _report.AppendLine("</table>"); db.SaveChanges(); msEnd = sw.ElapsedMilliseconds; _Logger.DebugFormat("Dauer {0}ms", msEnd - msStart); msg = $"Kurs {course.ShortName} mit Terminen importiert"; return(msg); }