public static void SetDefaultsForNew(this BlogEntry blogEntry, Blog blog, UserProfile userProfile) { if (blog == null) { throw new ArgumentNullException("blog"); } StoreFront storeFront = blog.StoreFront; blogEntry.SetDefaults(userProfile); blogEntry.Client = storeFront.Client; blogEntry.ClientId = storeFront.ClientId; blogEntry.StoreFront = storeFront; blogEntry.StoreFrontId = storeFront.StoreFrontId; blogEntry.Blog = blog; blogEntry.BlogId = blog.BlogId; blogEntry.Name = "New Blog Post"; blogEntry.UrlName = blogEntry.Name.FixUrlName(); if (!blog.BlogEntries.Any()) { blogEntry.Order = 1000; } else { blogEntry.Order = blog.BlogEntries.Max(be => be.Order) + 10; if (blog.BlogEntries.Any(be => be.Name.ToLower() == blogEntry.Name.ToLower() || be.UrlName.ToLower() == blogEntry.UrlName.ToLower())) { bool conflict = true; int index = 0; do { index++; blogEntry.Name = "New Blog Entry " + index; blogEntry.UrlName = blogEntry.Name.FixUrlName(); conflict = blog.BlogEntries.Any(be => be.Name.ToLower() == blogEntry.Name.ToLower() || be.UrlName.ToLower() == blogEntry.UrlName.ToLower()); } while (conflict); } } blogEntry.PostDateTimeUtc = DateTime.UtcNow; blogEntry.ShowInListEvenIfNoPermission = true; blogEntry.IsPending = false; blogEntry.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); blogEntry.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); }