示例#1
0
        public ActionResult Add()
        {
            var model = new AddChapterViewModel
            {
                ExtendedStory = this.GetStoriesForExtension(),
                PreviousChapterSelect = this.GetPreviousAvailableChapters()
            };

            return this.View(model);
        }
示例#2
0
        public ActionResult Add(AddChapterViewModel model)
        {
            var isTitleUnique = this.chapterService.IsTitleUnique(model.Title);
            if (!this.ModelState.IsValid ||
                !isTitleUnique)
            {
                model.PreviousChapterSelect = this.GetPreviousAvailableChapters();
                model.ExtendedStory = this.GetStoriesForExtension();
                model.Content = model.Content ?? string.Empty;

                if (!isTitleUnique)
                {
                    this.ModelState.AddModelError(string.Empty, "Title already in use!");
                }

                return this.View(model);
            }

            int? previousChapterId = null;
            if (model.PreviousChapterSelectId != -1)
            {
                previousChapterId = model.PreviousChapterSelectId;
            }

            var chapterToAdd = new Chapter
            {
                Content = model.Content,
                PreviousChapterId = previousChapterId,
                StoryId = model.ExtendedStoryId,
                AuthorId = this.UserId,
                Title = model.Title
            };

            this.chapterService.Add(chapterToAdd);
            this.TempData["Notification"] = "Congratulations! Chapter successfully added!";
            return this.RedirectToAction("Index", "Home");
        }