Example #1
0
        public ActionResult AddBlog()
        {
            // Create a new blog to be passed to the edit blog action
            Blog blog = new Blog
            {
                IsActive = false,
                Title    = "New Blog",
                Date     = DateTime.UtcNow,
                Tags     = new List <BlogTag> {
                    Utils.GetNewBlogTag()
                },
                BlogAuthor = Context.BlogUsers.First(usr => usr.UserId == 1) // This is anonymous and can't be deleted
            };

            var cat = Utils.GetUncategorizedCategory();

            blog.Category = cat;

            Context.Blogs.Add(blog);
            Context.SaveChanges();

            // Update the blog title / permalink with the new id we now have
            var blogId = blog.BlogId.ToString();

            blog.Title = blog.Title + " " + blogId;
            Context.SaveChanges();

            return(RedirectToAction("EditBlog", "Blog", new { id = blogId }));
        }