// GET: ChapterController/Details/5 public ActionResult Details(int id) { var chapter = _unitOfWork.Chapter.GetChapterById(id); var viewmodel = new CreateChapterViewModel { NameChapter = chapter.NameChapter, TextChapter = chapter.TextChapter }; return(View(viewmodel)); }
public async Task <IActionResult> CreateChapter(int id) { var fanfic = await _unitOfWork.Fanfic.GetByIdAsync(id); var viewmodel = new CreateChapterViewModel() { Fanfics = fanfic }; return(View(viewmodel)); }
public async Task <IActionResult> CreateChapter(CreateChapterViewModel vm) { if (ModelState.IsValid) { var chapter = new Chapter { Note = vm.Note, Title = vm.Title, Body = vm.Body }; var post = _repo.GetPost(vm.PostId); post.Chapters.Add(chapter); _repo.UpdatePost(post); await _repo.SaveChangesAsync(); return(RedirectToAction("Chapter", new { id = vm.PostId, idC = vm.PostId })); } else { //ModelState.AddModelError(string.Empty, "Заполните все поля!"); return(View("CreateChapter", vm)); } }
public async Task <IActionResult> Create(int id, CreateChapterViewModel chapterViewModel) { try { var fanfic = await _unitOfWork.Fanfic.GetByIdAsync(id); var user = fanfic.ApplicationUser; var chapter = new Chapter() { NameChapter = chapterViewModel.NameChapter, TextChapter = chapterViewModel.TextChapter, Fanfics = fanfic, ApplicationUser = user }; _unitOfWork.Chapter.AddChapter(chapter); await _unitOfWork.SaveAsync(); return(RedirectToAction("FanficList", "Fanfic")); } catch { return(View("Create")); } }