public IActionResult PostConfirm([Bind("Header, Body")] Story story)
 {
     if (ModelState.IsValid)
     {
         storyRepository.AddStory(story);
         return(View("PostConfirm", story));
     }
     return(View("StoryForm"));
 }
Ejemplo n.º 2
0
        public RedirectToActionResult Stories(string title, string author, string date, string text)
        {
            StoryResponse story = new StoryResponse();

            story.Title  = title;
            story.Date   = date; //for now Date is a string
            story.Text   = text;
            story.Author = new User()
            {
                Username = author
            };
            ViewBag.newestStory = title;
            repo.AddStory(story);
            return(RedirectToAction("UserStories"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> HappyTail(Story model)
        {
            // if model is valid, store in database
            if (ModelState.IsValid)
            {
                // Add logged in user to the model
                model.User = await userManager.GetUserAsync(User);

                // Add date and time of submission
                model.Date = DateTime.Now;
                // Add model to the database
                repo.AddStory(model);
                // Redirect user to the HappyTails view
                return(Redirect("HappyTails"));
            }
            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Story> > PostStory(Story story)
        {
            // If the story is not empty, post to database
            if (story != null)
            {
                // Add logged in user to the model
                story.User = await userManager.GetUserAsync(User);

                // Add date and time of submission
                story.Date = DateTime.Now;
                // Add story to database
                repo.AddStory(story);
                // Return OK
                return(Ok(story));
            }
            // Otherwise it's a BadRequest
            return(BadRequest());
        }
Ejemplo n.º 5
0
        public ViewResult StoriesForm(Story storiesResponse)
        {
            if (ModelState.IsValid)
            {
                //create new user for name entered in story form
                User u = new User()
                {
                    Name = storiesResponse.Name
                };

                //add story and corresponding user to repository
                repo.AddStory(storiesResponse, u);

                return(View("Thanks", storiesResponse));
            }

            else
            {
                //validation error
                return(View());
            }
        }