static public ReplacementModel FromDTO(Replacement dto) { ReplacementModel model = null; if (dto != null) { model = new ReplacementModel(); var coursesDAO = new MSSQLCourseDAO(); model.Replaced = Courses.Mapper.FromDTO(coursesDAO.FindCourseById(dto.ReplacedID)); var replacementsCoursesDAO = new MSSQLReplacementsCoursesDAO(); foreach (ReplacementCourse rc in replacementsCoursesDAO.FindByReplacementId(dto.Id)) { model.AddCourse(Courses.Mapper.FromDTO(coursesDAO.FindCourseById(rc.courseID))); } } return(model); }
public List <ReplacementModel> GetReplacementsFromData() { List <ReplacementModel> rml = new List <ReplacementModel>(); if (_replacedModel != null) { IReplacementDAO replacementDAO = new MSSQLReplacementDAO(); IReplacementsCoursesDAO replacementsCoursesDAO = new MSSQLReplacementsCoursesDAO(); try { List <Replacement> replacements = replacementDAO.FindByReplacedId(_replacedModel.Id); CoursesModel coursesModel = new CoursesModel(); foreach (Replacement r in replacements) { ReplacementModel replacementModel = new ReplacementModel(); replacementModel.Replaced = _replacedModel; List <ReplacementCourse> replacements_courses = replacementsCoursesDAO.FindByReplacementId(r.Id); foreach (ReplacementCourse rc in replacements_courses) { replacementModel.AddCourse(coursesModel.GetCourseByID(rc.courseID)); } rml.Add(replacementModel); } } catch (NoDatasourceConnectionException e) { Debug.WriteLine(e.Message); throw new DataServiceException(); } } return(rml); }