public ActionResult SubmitWordSeries([FromBody] SubmitWordsViewModel model) { var userId = GetUser().Id; if (model.Book.Id == 0) { model.Book.Id = _bookRepository.Add(new Book { Name = model.Book.Name, TargetLanguageId = model.Book.TargetLanguageId, BaseLanguageId = model.Book.BaseLanguageId }, userId).Id; if (model.Chapter != null) { model.Chapter.Id = _chapterRepository.Add(new Chapter { Name = model.Chapter.Name, BookId = model.Book.Id, }, userId).Id; } } if (model.Chapter?.Id == 0) { model.Chapter.Id = _chapterRepository.Add(new Chapter { Name = model.Chapter.Name, BookId = model.Book.Id, }, userId).Id; } _wordRepository.SubmitWordSeries(new SubmitWordsModel { BaseLanguage = new NameIdModel { Id = model.BaseLanguage.Id, Name = model.BaseLanguage.Name }, TargetLanguage = new NameIdModel { Id = model.TargetLanguage.Id, Name = model.TargetLanguage.Name }, Book = model.Book != null ? new Book { Id = model.Book.Id } : new Book(), Chapter = model.Chapter != null ? new Chapter { Id = model.Chapter.Id } : new Chapter(), Words = model.Words.Select(x => new FormWords { Base = new FormWord { Value = x.Base.Value }, Targets = x.Targets.Select(y => new FormWord { Value = y.Value }).ToList() }).ToList() }, userId); return(Ok()); }
public void AddChapter([FromBody] AddChapterModel chapter) { foreach (var item in chapter.ChaptersModel) { List <FreetextQModel> fqList = new List <FreetextQModel>(); List <MultiChoiceQModel> mcList = new List <MultiChoiceQModel>(); foreach (var items in chapter.FreetextQModel) { if (item.ChapterID == items.ChapterID) { fqList.Add(items); } } foreach (var items in chapter.MultiChoiceQModel) { if (item.ChapterID == items.ChapterID) { mcList.Add(items); } } var newChapter = new Chapter { Title = item.Title }; var chapterItem = _cr.Add(newChapter); AddFreeQuestionRange(fqList, chapterItem.ID, chapter.SurveyID); AddMultiQuestionRange(mcList, chapterItem.ID, chapter.SurveyID); } }
public IActionResult SaveChapter(EditChapterViewModel viewModel) { if (!DateTime.TryParse(viewModel.Date, out var date)) { ModelState.AddModelError("Date", "Date is invalid"); } if (!ModelState.IsValid) { return(View("EditChapter", viewModel)); } Chapter chapter; if (viewModel.Id == null) { chapter = new Chapter(); chapter.DiaryId = viewModel.DiaryId; _chapterRepository.Add(chapter); } else { chapter = _chapterRepository.GetById(viewModel.Id.Value); } chapter.Name = viewModel.Title; chapter.Location = viewModel.Location; chapter.Date = date; chapter.IsPublic = viewModel.IsPublic; chapter.Content = viewModel.Content; if (viewModel.Image != null) { using var stream = viewModel.Image.OpenReadStream(); var imageBytes = new byte[stream.Length]; stream.Read(imageBytes); if (chapter.Image != null) { chapter.Image.Content = imageBytes; } else { chapter.Image = new AtwImage() { Content = imageBytes }; } } _chapterRepository.SaveChanges(); return(RedirectToAction("EditDiary", "Diary", new { id = chapter.DiaryId })); }
public ActionResult <Priority> PostChapter(ChapterDTO chapter) { // Priority priority = _chapterRepository.getPriorityById(chapter.Priority.Id); // Theme theme = _chapterRepository.getThemeById(chapter.Theme.Id); Chapter newChapter = new Chapter() { Title = chapter.Title, Priority = chapter.Priority == null ? null : _chapterRepository.getPriorityById(chapter.Priority.Id), Theme = chapter.Theme == null ? null : _chapterRepository.getThemeById(chapter.Theme.Id), Date = chapter.Date }; _chapterRepository.Add(newChapter); _chapterRepository.SaveChanges(); return(CreatedAtAction(nameof(GetAllChaptersByThemeOrPriority), new { id = newChapter.Id }, newChapter)); }
private void AddChapters(int comicId, IChapterRepository chapterRepository, ICollection<Chapter> chapters) { if (chapters == null) return; foreach (Chapter chapter in chapters) { chapter.ComicId = comicId; if (chapter.ReleaseDate < new DateTime(1910, 1, 1)) { chapter.ReleaseDate = new DateTime(1910, 1, 1); } Chapter chapterDb = chapterRepository.Find(c => c.ChapterUrl.Equals(chapter.ChapterUrl)).FirstOrDefault(); if (chapterDb == null) { chapterRepository.Add(chapter); } } chapterRepository.Save(); }