public IResult Create(Post entity, int subCategoryId) { _postDal.Add(entity); PostStat postStat = new PostStat(); postStat.PostStatId = entity.PostId; postStat.Views = 0; postStat.Claps = 0; _postStatService.Create(postStat); return(new SuccessResult()); }
//public Post GetMostPopularPostByCategory(int categoryId) //{ // //var post = (from p in _context.Posts // // join s in _context.SubCategoryPosts // // on p.PostId equals s.PostId // // join c in _context.SubCategories // // on s.SubCategoryId equals c.SubCategoryId // // join m in _context.Categories // // on c.CategoryId equals m.CategoryId // // where c.CategoryId == categoryId && p.IsPublished == true // // select p).OrderByDescending(p => p.PostStat.Views).First(); // //return post; //} public Post AddPostWithStatsAndCategory(Post post, int subCategoryId) { _context.Posts.Add(post); PostStat postStat = new PostStat(); postStat.PostStatId = post.PostId; postStat.Views = 0; postStat.Claps = 0; _context.PostStats.Add(postStat); _context.SaveChanges(); return(post); }
private void AddPostViewToStat(int postId) { PostStat postStat = db.PostStats.SingleOrDefault(post => post.PostId == postId); // If it's the first time the post is viewed if (postStat == null) { db.PostStats.Add(new PostStat { PostId = postId, Counter = 1 }); } else { postStat.Counter = postStat.Counter + 1; } db.SaveChanges(); }
protected override void Seed(Sahika.DataAccess.Concrete.SahikaContext context) { List <ApplicationUser> Users = new List <ApplicationUser>(); for (int i = 4; i < 20; i++) { ApplicationUser user = new ApplicationUser(); user.UserName = FakeData.NameData.GetFullName(); user.Email = FakeData.NetworkData.GetEmail(); user.EmailConfirmed = true; user.PhoneNumber = FakeData.PhoneNumberData.GetPhoneNumber(); user.PhoneNumberConfirmed = true; Users.Add(user); context.Users.Add(user); } context.SaveChanges(); List <Post> Posts = new List <Post>(); for (int i = 0; i < 15; i++) { Post post = new Post(); post.Title = FakeData.TextData.GetSentence(); post.Body = FakeData.TextData.GetSentence(); post.DateCreated = FakeData.DateTimeData.GetDatetime(); post.UserId = i + 1; Posts.Add(post); context.Posts.Add(post); } context.SaveChanges(); List <Category> Categories = new List <Category>(); for (int i = 0; i < 5; i++) { Category category = new Category(); category.CategoryName = FakeData.TextData.GetSentence(); category.DateCreated = FakeData.DateTimeData.GetDatetime(); Categories.Add(category); context.Categories.Add(category); } context.SaveChanges(); List <SubCategory> SubCategories = new List <SubCategory>(); for (int i = 0; i < 5; i++) { SubCategory subCategory = new SubCategory(); subCategory.SubCategoryName = FakeData.TextData.GetSentence(); subCategory.CategoryId = i + 1; SubCategories.Add(subCategory); context.SubCategories.Add(subCategory); } context.SaveChanges(); List <PostComment> PostComments = new List <PostComment>(); for (int i = 1; i < 5; i++) { for (int j = 6; j < 9; j++) { PostComment postComment = new PostComment(); postComment.PostId = j; postComment.UserId = i; postComment.Comment = FakeData.TextData.GetSentence(); PostComments.Add(postComment); context.PostComments.Add(postComment); } } context.SaveChanges(); List <FavouritePost> FavouritePosts = new List <FavouritePost>(); for (int i = 1; i < 5; i++) { FavouritePost favouritePost = new FavouritePost(); favouritePost.UserId = 1; favouritePost.PostId = i + 2; FavouritePosts.Add(favouritePost); context.FavouritePosts.Add(favouritePost); } context.SaveChanges(); List <FavouritePost> FavouritePosts2 = new List <FavouritePost>(); for (int i = 5; i < 10; i++) { FavouritePost favouritePost = new FavouritePost(); favouritePost.UserId = 2; favouritePost.PostId = i; FavouritePosts2.Add(favouritePost); context.FavouritePosts.Add(favouritePost); } context.SaveChanges(); List <FavouritePost> FavouritePosts3 = new List <FavouritePost>(); for (int i = 10; i < 15; i++) { FavouritePost favouritePost = new FavouritePost(); favouritePost.UserId = 3; favouritePost.PostId = i; FavouritePosts3.Add(favouritePost); context.FavouritePosts.Add(favouritePost); } context.SaveChanges(); List <PostStat> PostStats = new List <PostStat>(); for (int i = 0; i < 10; i++) { PostStat postStat = new PostStat(); postStat.PostStatId = i + 1; postStat.Views = i + 25; postStat.Claps = i + 35; PostStats.Add(postStat); context.PostStats.Add(postStat); } context.SaveChanges(); }
public IResult Create(PostStat entity) { _postStatDal.Add(entity); return(new SuccessResult()); }