Esempio n. 1
0
        public ActionResult CreateStory(ShortStoryInputViewModel shortStory)
        {
            if (!this.User.Identity.IsAuthenticated)
            {
                this.Response.StatusCode = 401;
                return(this.Content("Access is denied"));
            }

            shortStory.Tags     = this.tags.GetAll().To <TagViewModel>();
            shortStory.AuthorId = this.User.Identity.GetUserId();

            if (!this.ModelState.IsValid)
            {
                return(this.View(shortStory));
            }
            var newStory = new ShortStory()
            {
                Title    = shortStory.Title,
                Content  = shortStory.Content,
                AuthorId = shortStory.AuthorId
            };

            foreach (var id in shortStory.TagIds)
            {
                newStory.Tags.Add(this.tags.GetById(id));
            }

            this.stories.Add(newStory);


            var viewModel = this.Mapper.Map <ShortStoryDetailsViewModel>(newStory);


            return(this.RedirectToAction("Details", "ShortStories", new { id = viewModel.Id, area = "ShortStory" }));
        }
Esempio n. 2
0
        public ActionResult CreateStory(ShortStoryInputViewModel shortStory)
        {
            if (!this.User.Identity.IsAuthenticated)
            {
                this.Response.StatusCode = 401;
                return this.Content("Access is denied");
            }

            shortStory.Tags = this.tags.GetAll().To<TagViewModel>();
            shortStory.AuthorId = this.User.Identity.GetUserId();

            if (!this.ModelState.IsValid)
            {
                return this.View(shortStory);
            }
            var newStory = new ShortStory()
            {
                Title = shortStory.Title,
                Content = shortStory.Content,
                AuthorId = shortStory.AuthorId
            };

            foreach (var id in shortStory.TagIds)
            {
                newStory.Tags.Add(this.tags.GetById(id));
            }

            this.stories.Add(newStory);

            var viewModel = this.Mapper.Map<ShortStoryDetailsViewModel>(newStory);

            return this.RedirectToAction("Details", "ShortStories", new { id = viewModel.Id, area = "ShortStory" });
        }
Esempio n. 3
0
        public ActionResult CreateStory(string id)
        {
            if (id == null)
            {
                this.Response.StatusCode = 404;
                return(this.Content("User was not found"));
            }

            var viewModel = new ShortStoryInputViewModel()
            {
                AuthorId = id,
                Tags     = this.tags.GetAll().To <TagViewModel>()
            };

            return(this.View(viewModel));
        }
Esempio n. 4
0
        public ActionResult CreateStory(string id)
        {
            if (id == null)
            {
                this.Response.StatusCode = 404;
                return this.Content("User was not found");
            }

            var viewModel = new ShortStoryInputViewModel()
            {
                AuthorId = id,
                Tags = this.tags.GetAll().To<TagViewModel>()
            };

            return this.View(viewModel);
        }