コード例 #1
0
        public ActionResult Create(PostEditModel model)
        {
            ViewBag.Title = "Create";
            if (ModelState.IsValid)
            {
                var url = PostHelpers.MakeUrl(_dateTime.Today.Year, _dateTime.Today.Month, _dateTime.Today.Day, model.Title);

                _postRepository.Create(new Post
                {
                    AuthorId         = _securityHelper.CurrentUser.Id,
                    DraftBody        = model.Body,
                    DraftDescription = model.Description,
                    Posted           = _dateTime.Now,
                    DraftTitle       = model.Title,
                    Status           = PostStatus.Draft,
                    Path             = url,
                    Canonical        = model.Reposted ? model.CanonicalUrl : "/" + url,
                    ExcludeFromFeed  = false,
                    PostGuid         = Guid.NewGuid(),
                    BlogId           = CurrentBlog.Id
                });

                return(RedirectToAction("Index", "Dashboard"));
            }
            return(View("Edit", model));
        }
コード例 #2
0
        public ActionResult RebuildAllUrls()
        {
            var posts = _postRepository.PostsForBlog(CurrentBlog.Id).ToList();

            foreach (var post in posts)
            {
                post.Path = PostHelpers.MakeUrl(post.Posted.Year, post.Posted.Month, post.Posted.Day, post.Title);
                _postRepository.Update(post);
            }
            return(RedirectToAction("Index", "Dashboard"));
        }
コード例 #3
0
        protected override void Seed(StaticVoid.Blog.Data.BlogContext context)
        {
#if DEBUG
#if !DISABLE_SEED
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            var admin = new User
            {
                Id = 1,
                ClaimedIdentifier = "",
                Email             = "*****@*****.**",
                FirstName         = "Luke",
                LastName          = "McGregor",
                IsAuthor          = true
            };

            context.Users.AddOrUpdate(admin);

            var blogCreatorSecurable = new Securable {
                Name = "Blog Creator", Members = new List <User> {
                    admin
                }
            };
            context.Securables.AddOrUpdate(blogCreatorSecurable);

            if (!context.Blogs.Any())
            {
                var blog = new Data.Blog
                {
                    AuthoritiveUrl = "http://*****:*****@staticv0id",
                    Style          = new Style
                    {
                        Css =
                            @".test{
}"
                    },
                    AuthorSecurable = new Securable {
                        Name = "Author : StaticVoid - Test"
                    }
                };

                context.Blogs.AddOrUpdate(blog);
            }

            var postDate = new DateTime(2012, 10, 7, 12, 0, 0);

            context.Posts.AddOrUpdate(
                new Post
            {
                Id        = 1,
                AuthorId  = 1,
                Title     = "First Post",
                Body      = "First Post!",
                Posted    = postDate,
                Status    = PostStatus.Published,
                Path      = PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "First Post"),
                Canonical = "/" + PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "First Post")
            });

            postDate = postDate.AddDays(1);
            context.Posts.AddOrUpdate(
                new Post
            {
                Id        = 2,
                AuthorId  = 1,
                Title     = "Second Post",
                Body      = "Second Post!",
                Posted    = postDate,
                Status    = PostStatus.Published,
                Path      = PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "Second Post"),
                Canonical = "/" + PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "Second Post")
            });
#endif
#endif
        }