Beispiel #1
0
 public void AddTag(Page page, string tagName)
 {
     page.Tags.Add(new Tag
     {
         Name = tagName
     });
 }
Beispiel #2
0
 public void AddDislike(Page page, User user)
 {
     page.Dislikes.Add(new Dislike
     {
         PageId = page.Id,
         UserId = user.Id
     });
 }
Beispiel #3
0
 public void AddLike(Page page, User user)
 {
     page.Likes.Add(new Like
     {
         PageId = page.Id,
         UserId = user.Id
     });
 }
Beispiel #4
0
 public void AddComment(Page page, User user, string content)
 {
     page.Comments.Add(new Comment
     {
         AuthorId = user.Id,
         PageId = page.Id,
         Content = content
     });
 }
Beispiel #5
0
 public int GetPageRating(Page page)
 {
     return page.Likes.Where(l => !l.IsDeleted).Count() - page.Dislikes.Where(l => !l.IsDeleted).Count();
 }
Beispiel #6
0
 private void AddRandomTagsToPage(Page page, int count)
 {
     for (int j = 0; j < count; j++)
     {
         this.AddTag(page, this.randomGenerator.RandomString(3, 15));
     }
 }
Beispiel #7
0
 private void AddInitialRandomLikeDislikeToPage(Page page)
 {
     if (this.randomGenerator.RandomNumber(0, 2) == 0)
     {
         this.AddLike(page, page.User);
     }
     else
     {
         this.AddDislike(page, page.User);
     }
 }
Beispiel #8
0
        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();
        }
Beispiel #9
0
        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();
        }
Beispiel #10
0
 public void SeedRandomLikes(Page page, IList<User> users, int count)
 {
     for (int i = 0; i < count; i++)
     {
         this.AddLike(page, this.GetRandomUser(users));
     }
 }
Beispiel #11
0
 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());
     }
 }