Exemplo n.º 1
0
        public ActionResult Create_Post()
        {
            var blogPost = new BlogPost();
            // analogous to receiving the blogPost as a paramater
            if (!TryUpdateModel(blogPost))
            {
                //...
            }

            if (ModelState.IsValid)
            {
                BlogPostService.Add(blogPost);
                return RedirectToAction("Index");
            }
            else // data is invalid
            {
                return View(blogPost);
            }
        }
Exemplo n.º 2
0
 public void Add(BlogPost blogPost)
 {
     blogPost.Id = _blogPosts.Last().Id + 1;
     _blogPosts.Add(blogPost);
 }
Exemplo n.º 3
0
 public ActionResult Create()
 {
     var initialBlogPost = new BlogPost {PublishedOnDate = DateTime.Now.Date};
     return View(initialBlogPost);
 }