public static ViewTopicModel ToViewTopicModel(this Topic topic, IDisciplineStorage storage) { return(new ViewTopicModel { Id = topic.Id, ChapterId = topic.ChapterRef, Created = ToString(topic.Created), Updated = ToString(topic.Updated), TestCourseName = topic.TestCourseRef.HasValue && topic.TestCourseRef != Constants.TestWithoutCourseId ? (storage.GetCourse(topic.TestCourseRef.Value) == null ? Localization.GetMessage("course deleted") : storage.GetCourse(topic.TestCourseRef.Value).Name) : string.Empty, TestTopicType = topic.TestTopicTypeRef.HasValue ? ToString( storage.GetTopicType(topic.TestTopicTypeRef.Value)) : string.Empty, TheoryCourseName = topic.TheoryCourseRef.HasValue ? (storage.GetCourse(topic.TheoryCourseRef.Value) == null ? Localization.GetMessage("course deleted") : storage.GetCourse(topic.TheoryCourseRef.Value).Name) : string.Empty, TheoryTopicType = topic.TheoryTopicTypeRef.HasValue ? ToString( storage.GetTopicType(topic.TheoryTopicTypeRef.Value)) : string.Empty, TopicName = topic.Name }); }
private void Serialize(string path, int disciplineId) { var discipline = this.storage.GetDiscipline(disciplineId); var disciplineDto = new DisciplineDto { Name = discipline.Name, Chapters = this.storage.GetChapters(item => item.DisciplineRef == discipline.Id) .Select(chapter => new ChapterDto { Name = chapter.Name, Topics = this.storage.GetTopics(item => item.ChapterRef == chapter.Id) .OrderBy(item => item.SortOrder) .Select(topic => new TopicDto { Name = topic.Name, TestCourseName = topic.TestCourseRef == null ? string.Empty : string.Format("{0}-Test_{1}", storage.GetCourse((int)topic.TestCourseRef).Name, (int)topic.TestCourseRef), TestTopicTypeRef = topic.TestTopicTypeRef, TheoryCourseName = topic.TheoryCourseRef == null ? string.Empty : string.Format("{0}-Theory_{1}", storage.GetCourse((int)topic.TheoryCourseRef).Name, (int)topic.TheoryCourseRef), TheoryTopicTypeRef = topic.TheoryTopicTypeRef }).ToList() }).ToList() }; Stream writer = new FileStream(path, FileMode.Create); var serializer = new XmlSerializer(disciplineDto.GetType()); serializer.Serialize(writer, disciplineDto); writer.Close(); }
public static ViewTopicModel ToViewTopicModel(this Topic topic, IDisciplineStorage storage) { return new ViewTopicModel { Id = topic.Id, ChapterId = topic.ChapterRef, Created = ToString(topic.Created), Updated = ToString(topic.Updated), TestCourseName = topic.TestCourseRef.HasValue && topic.TestCourseRef != Constants.TestWithoutCourseId ? (storage.GetCourse(topic.TestCourseRef.Value) == null ? Localization.GetMessage("course deleted") : storage.GetCourse(topic.TestCourseRef.Value).Name) : string.Empty, TestTopicType = topic.TestTopicTypeRef.HasValue ? ToString( storage.GetTopicType(topic.TestTopicTypeRef.Value)) : string.Empty, TheoryCourseName = topic.TheoryCourseRef.HasValue ? (storage.GetCourse(topic.TheoryCourseRef.Value) == null ? Localization.GetMessage("course deleted") : storage.GetCourse(topic.TheoryCourseRef.Value).Name) : string.Empty, TheoryTopicType = topic.TheoryTopicTypeRef.HasValue ? ToString( storage.GetTopicType(topic.TheoryTopicTypeRef.Value)) : string.Empty, TopicName = topic.Name }; }