Skip to content

Commit

Permalink
Simplify seed data
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco committed Jun 6, 2017
1 parent c6ee2f8 commit ec00193
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/Bloggy/Models/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class Post

public string Tags { get; set; }

public virtual IEnumerable<Comment> Comments { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
}
108 changes: 23 additions & 85 deletions src/Bloggy/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, Blo
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
AddTestData();
AddSeedData();
}
else
{
Expand All @@ -77,101 +77,39 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, Blo
app.UseMvc();
}

private void AddTestData()
private void AddSeedData()
{
Db.Posts.AddRange(
new Post
for (int i = 1; i <= 10; i++)
{
var post = new Post
{
Id = 1,
Id = i,
Title = "What is Lorem Ipsum?",
Slug = "what-is-lorem-ipsum-1",
Slug = "what-is-lorem-ipsum-" + i,
Excerpt = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
Content = @"**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. **Lorem Ipsum** has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing **Lorem Ipsum** passages, and more recently with desktop publishing software like Aldus PageMaker including versions of **Lorem Ipsum**.",
IsPublished = true,
PublishedAt = new DateTime(2016, 12, 2),
Tags = "Lorem Ipsum,lorem,ipsum"
},
new Post
{
Id = 2,
Title = "Where does it come from?",
Slug = "where-does-it-come-from-2",
Excerpt = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
Content = @"**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. **Lorem Ipsum** has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing **Lorem Ipsum** passages, and more recently with desktop publishing software like Aldus PageMaker including versions of **Lorem Ipsum**.",
IsPublished = true,
PublishedAt = new DateTime(2016, 12, 4),
Tags = "Lorem Ipsum,lorem,ipsum"
},
new Post
{
Id = 3,
Title = "Why do we use it?",
Slug = "why-do-we-use-it-3",
Excerpt = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
Content = @"**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. **Lorem Ipsum** has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing **Lorem Ipsum** passages, and more recently with desktop publishing software like Aldus PageMaker including versions of **Lorem Ipsum**.",
IsPublished = true,
PublishedAt = new DateTime(2016, 11, 6),
Tags = "Lorem Ipsum,lorem,ipsum"
},
new Post
{
Id = 4,
Title = "What is Lorem Ipsum?",
Slug = "what-is-lorem-ipsum-4",
Excerpt = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
Content = @"**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. **Lorem Ipsum** has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing **Lorem Ipsum** passages, and more recently with desktop publishing software like Aldus PageMaker including versions of **Lorem Ipsum**.",
IsPublished = true,
PublishedAt = new DateTime(2015, 12, 8),
Tags = "Lorem Ipsum,lorem,ipsum"
},
new Post
{
Id = 5,
Title = "Where does it come from?",
Slug = "where-does-it-come-from-5",
Excerpt = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
Content = @"**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. **Lorem Ipsum** has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of **Lorem Ipsum**.
Contrary to popular belief, **Lorem Ipsum** is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of ""de Finibus Bonorum et Malorum"" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, ""Lorem ipsum dolor sit amet.."", comes from a line in section 1.10.32.
};
post.Comments = new List<Comment>();

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from ""de Finibus Bonorum et Malorum"" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
IsPublished = true,
PublishedAt = new DateTime(2016, 12, 10),
Tags = "Lorem Ipsum,lorem,ipsum",
Comments = new List<Comment>
{
new Comment()
{
Author = "Lorem Ipsum",
Email = "lorem@ipsum.com",
Content = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
Website = "http://www.lipsum.com",
PublishedAt = new DateTime(2016,12,14),
PostId = 5
},
new Comment()
{
Author = "Lorem Ipsum",
Email = "lorem@ipsum.com",
Content = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
Website = "http://www.lipsum.com",
PublishedAt = new DateTime(2016,12,14),
PostId = 5
}
}
},
new Post
for (int j = 1; j < 3; j++)
{
Id = 6,
Title = "Why do we use it?",
Slug = "why-do-we-use-it-6",
Excerpt = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
Content = @"**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. **Lorem Ipsum** has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing **Lorem Ipsum** passages, and more recently with desktop publishing software like Aldus PageMaker including versions of **Lorem Ipsum**.",
LastModified = new DateTime(2016, 12, 10),
IsPublished = false,
Tags = "Lorem Ipsum,lorem,ipsum"
var comment = new Comment()
{
Author = "Lorem Ipsum",
Email = "lorem@ipsum.com",
Content = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
Website = "http://www.lipsum.com",
PublishedAt = new DateTime(2016, 12, 14),
PostId = i,
Post = post
};
post.Comments.Add(comment);
}
);
Db.Posts.Add(post);
}

Db.SaveChanges();
}
Expand Down

0 comments on commit ec00193

Please sign in to comment.