public IActionResult UserStoryChapterSectionsRead(string storyId, string chapterId) { var Model = new ChapterSectionModel(); var Story = _context.Storys.Where(x => x.Id == storyId); foreach (var DBStory in Story) { Model.Story = new StoryModel { Id = DBStory.Id, Title = DBStory.Title, Description = DBStory.Description, Gender = DBStory.Gender }; } var DBChapterP = _context.Chapters.Include(x => x.Sections); var Chapter = DBChapterP.Where(x => x.Id == chapterId); foreach (var DBChapter in Chapter) { Model.Chapter = new StoryChapters { Id = DBChapter.Id, Seq = DBChapter.Seq, Title = DBChapter.Title, Description = DBChapter.Description }; Model.Sections = new List <SectionModel>(); foreach (var Section in DBChapter.Sections) { Model.Sections.Add(new SectionModel { Id = Section.Id, Seq = Section.Seq, Text = Section.Text == null ? "" : Section.Text }); } Model.Sections = Model.Sections.OrderBy(x => x.Seq).ToList(); } if (Model.Chapter == null) { Model.Chapter = new StoryChapters { Seq = 1, Title = "", Description = "" }; } if (Model.Sections == null) { Model.Sections = new List <SectionModel>(); Model.Sections.Add(new SectionModel { Seq = 1, Text = "" }); } return(View(Model)); }
public IActionResult UserStoryChapterSectionsCreateEdit(string storyId, string chapterId) { var Model = new ChapterSectionModel(); var Story = _context.Storys.Where(x => x.User.Id == User.FindFirstValue(ClaimTypes.NameIdentifier) && x.Id == storyId); foreach (var DBStory in Story) { Model.Story = new StoryModel { Id = DBStory.Id, Title = DBStory.Title, Description = DBStory.Description, Gender = DBStory.Gender }; } var DBChapterP = _context.Chapters.Include(x => x.Sections); var Chapter = DBChapterP.Where(x => x.Id == chapterId); foreach (var DBChapter in Chapter) { Model.Chapter = new StoryChapters { Id = DBChapter.Id, Seq = DBChapter.Seq, Title = DBChapter.Title, Description = DBChapter.Description, Published = DBChapter.Published }; Model.Sections = new List <SectionModel>(); foreach (var Section in DBChapter.Sections) { Model.Sections.Add(new SectionModel { Id = Section.Id, Seq = Section.Seq, Text = Section.Text == null ? "" : Section.Text }); } Model.Sections = Model.Sections.OrderBy(x => x.Seq).ToList(); } if (Model.Chapter == null) { Model.Chapter = new StoryChapters { Seq = 1, Title = "", Description = "", Published = false }; } if (Model.Sections == null) { Model.Sections = new List <SectionModel>(); Model.Sections.Add(new SectionModel { Seq = 1, Text = "" }); } return(View(Model)); }