コード例 #1
0
        public ActionResult Create()
        {
            var model = new StoryCreateViewModel();

            model.Games = new SelectList(db.Games, "Id", "Title");
            return(View(model));
        }
コード例 #2
0
        public ActionResult Create(StoryCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = storyService.Add(new StoryModel
                {
                    Title       = model.Title,
                    Content     = model.Content,
                    Description = model.Description,
                    CreatorId   = CurrentUserId,
                    GroupIds    = model.GroupIds,
                });

                if (result)
                {
                    return(RedirectToAction("Index", "Story"));
                }
                else
                {
                    ModelState.AddModelError("", "Story creation failed");
                }
            }

            model.GroupListItems = GetGroupsListItems();
            return(View(model));
        }
コード例 #3
0
        public ActionResult Create()
        {
            var model = new StoryCreateViewModel
            {
                GroupListItems = GetGroupsListItems(),
            };

            return(View(model));
        }
コード例 #4
0
        public ActionResult Create(StoryCreateViewModel story)
        {
            if (!this.ModelState.IsValid)
            {
                return(View(story));
            }

            var storyDto = new StoryDto()
            {
                Title   = story.Title,
                Content = story.Content
            };
            var storyId = this.storyService.Create(storyDto, this.User.Identity.GetUserId());

            return(this.RedirectToAction("Details", new { id = storyId }));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "Title,Body,GameID")] StoryCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var story = new Story();
                story.Title   = model.Title;
                story.Body    = model.Body;
                story.Game_Id = model.GameID;
                story.Author  = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

                db.Stories.Add(story);
                db.SaveChanges();
                return(RedirectToAction("Details", "Stories", new { id = story.Id }));
            }

            return(View(model));
        }
コード例 #6
0
        public ActionResult Edit(Guid id)
        {
            var story = storyService.GetById(id);

            if (story != null && story.UserId == this.User.Identity.GetUserId())
            {
                var viewModel = new StoryCreateViewModel()
                {
                    Id      = story.Id,
                    Title   = story.Title,
                    Content = story.Content
                };
                return(View(viewModel));
            }

            return(new HttpNotFoundResult());
        }
コード例 #7
0
        public ActionResult Edit(StoryCreateViewModel story)
        {
            if (!this.ModelState.IsValid)
            {
                return(View(story));
            }

            var storyDto = new StoryDto()
            {
                Id      = story.Id,
                Title   = story.Title,
                Content = story.Content
            };

            this.storyService.Update(storyDto);

            return(this.RedirectToAction("Details", new { id = story.Id }));
        }