public void AddTag(Page page, string tagName) { page.Tags.Add(new Tag { Name = tagName }); }
public void AddDislike(Page page, User user) { page.Dislikes.Add(new Dislike { PageId = page.Id, UserId = user.Id }); }
public void AddLike(Page page, User user) { page.Likes.Add(new Like { PageId = page.Id, UserId = user.Id }); }
public void AddComment(Page page, User user, string content) { page.Comments.Add(new Comment { AuthorId = user.Id, PageId = page.Id, Content = content }); }
public int GetPageRating(Page page) { return page.Likes.Where(l => !l.IsDeleted).Count() - page.Dislikes.Where(l => !l.IsDeleted).Count(); }
private void AddRandomTagsToPage(Page page, int count) { for (int j = 0; j < count; j++) { this.AddTag(page, this.randomGenerator.RandomString(3, 15)); } }
private void AddInitialRandomLikeDislikeToPage(Page page) { if (this.randomGenerator.RandomNumber(0, 2) == 0) { this.AddLike(page, page.User); } else { this.AddDislike(page, page.User); } }
public void SeedSinglePage(ILikeItDbContext context, string name, string description, Category category, IList<string> tags, User user, Image image, bool like, string comment = "") { var page = new Page { Name = name, Category = category, Description = description, CreatedOn = DateTime.Now, User = user, Image = image, }; for (int i = 0; i < tags.Count; i++) { this.AddTag(page, tags[i]); } if (like) { this.AddLike(page, page.User); } else { this.AddDislike(page, page.User); } page.Rating = this.GetPageRating(page); if (!string.IsNullOrEmpty(comment)) { this.AddComment(page, page.User, comment); } context.Pages.Add(page); context.SaveChanges(); }
public void SeedRandomPages(LikeItDbContext context, IList<Category> categories, IList<User> users, int count) { var pages = new List<Page>(); for (int i = 0; i < count; i++) { var page = new Page { Name = this.randomGenerator.RandomString(5, 10), Category = categories[this.randomGenerator.RandomNumber(0, categories.Count - 1)], Description = this.randomGenerator.RandomString(20, 150), CreatedOn = DateTime.Now, User = this.GetRandomUser(users), Image = this.GetSampleImage(DeafultImagePath), }; this.AddRandomTagsToPage(page, this.randomGenerator.RandomNumber(1, 5)); this.AddInitialRandomLikeDislikeToPage(page); this.SeedRandomLikes(page, users, this.randomGenerator.RandomNumber(0, 20)); this.SeedRandomDislikes(page, users, this.randomGenerator.RandomNumber(0, 20)); this.SeedRandomComments(page, users, this.randomGenerator.RandomNumber(0, 4)); page.Rating = this.GetPageRating(page); pages.Add(page); } context.Pages.AddOrUpdate(pages.ToArray()); context.SaveChanges(); }
public void SeedRandomLikes(Page page, IList<User> users, int count) { for (int i = 0; i < count; i++) { this.AddLike(page, this.GetRandomUser(users)); } }
public void SeedRandomComments(Page page, IList<User> users, int count) { for (int i = 0; i < count; i++) { this.AddComment(page, this.GetRandomUser(users), this.randomGenerator.RandomString()); } }