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