Beispiel #1
0
        public ActionResult SubmitPost(BlogPost post)
        {
            BlogDb db = new BlogDb(_connectionString);

            post.DateCreated = DateTime.Now;
            db.AddPost(post);
            return(Redirect($"/home/viewblog?id={post.Id}"));
        }
Beispiel #2
0
        public ActionResult SubmitPost(BlogPost post)
        {
            BlogDb db = new BlogDb(Properties.Settings.Default.ConStr);

            post.DateCreated = DateTime.Now;
            db.AddPost(post);
            return(Redirect($"/home/viewblog?id={post.Id}"));
        }
Beispiel #3
0
        public ActionResult AddPost(string title, string text, string tags)
        {
            var db   = new BlogDb(_connectionString);
            var post = new Post {
                Date = DateTime.Now, Text = text, Title = title
            };

            db.AddPost(post);
            IEnumerable <Tag> postTags = tags.Split(',').Select(t =>
            {
                int tagId = db.AddTag(t);
                return(new Tag
                {
                    Id = tagId,
                    Name = t
                });
            });

            db.AddTagsToPost(post, postTags);
            return(RedirectToAction("Index", "Blog"));
        }