// ======================================================= // Methods // ======================================================= /// <summary> /// Create a new unit /// </summary> /// <param name="crs">The course to place the unit into</param> /// <returns></returns> public bool CreateNewUnit(Course crs) { try { Unit newUnit = new Unit(); newUnit.ID = Guid.NewGuid(); newUnit.CourseID = crs.ID; newUnit.Course = crs; newUnit.UnitName = "New Unit"; newUnit.UnitNumber = (crs.Units.Count + 1); crs.Units.Add(newUnit); return true; } catch { //An error occured return false; } }
/// <summary> /// Move a lesson into a unit /// </summary> /// <param name="lsn">The lesson to move</param> /// <param name="newUnt">The unit that the lesson is going into</param> /// <returns></returns> public bool MoveLesson(Lesson lsn, Unit newUnt) { try { lsn.UnitID = newUnt.ID; lsn.Unit = newUnt; //Remove the lesson from its current unit lsn.Unit.Lessons.Remove(lsn); //Move the lesson into its new unit newUnt.Lessons.Add(lsn); return true; } catch { //something went wrong return false; } }
/// <summary> /// Create a new lesson in the specified unit /// </summary> /// <param name="unt">The unit to create the lesson in</4param> /// <returns></returns> public bool CreateNewLesson(Unit unt) { try { Lesson newLesson = new Lesson(); newLesson.ID = Guid.NewGuid(); newLesson.UnitID = unt.ID; newLesson.Unit = unt; newLesson.LessonName = "New Lesson"; newLesson.LessonNum = (unt.Lessons.Count + 1); unt.Lessons.Add(newLesson); return true; } catch { return false; } }
/// <summary> /// Delete the specified lesson /// </summary> /// <param name="unt">The unit to be deleted</param> /// <returns></returns> public bool DeleteUnit(Unit unt) { try { //Remove the unit from the course's units list unt.Course.Units.Remove(unt); //Mark the unit for deletion return untContext.DeleteUnit(unt); } catch { return false; } }
/// <summary> /// Move a unit into a course /// </summary> /// <param name="unt">The unit to move</param> /// <param name="newCrs">The course that the unit is going into</param> /// <returns></returns> public bool MoveUnit(Unit unt, Course newCrs) { try { unt.CourseID = newCrs.ID; unt.Course = newCrs; //Remove the unit from its current course unt.Course.Units.Remove(unt); //Move the unit into its new course newCrs.Units.Add(unt); return true; } catch { //something went wrong return false; } }