Exemple #1
0
 public Postss Post(int postId)
 {
     using (var context = new PostgressContext())
     {
         return(context.Posts.FirstOrDefault(x => x.Id == postId));
     }
 }
Exemple #2
0
 public List <Categories> Categories()
 {
     using (var context = new PostgressContext())
     {
         return(context.Categories.ToList());
     }
 }
Exemple #3
0
 public List <Users> Users()
 {
     using (var context = new PostgressContext())
     {
         return(context.Users.ToList());
     }
 }
Exemple #4
0
 public List <Comments> CommentsToPost(int postId)
 {
     using (var context = new PostgressContext())
     {
         return(context.Comments.Where(x => x.PostId == postId).ToList());
     }
 }
Exemple #5
0
 public List <Postss> Posts()
 {
     using (var context = new PostgressContext())
     {
         return(context.Posts.ToList());
     }
 }
Exemple #6
0
 public void DeleteComm(int commId)
 {
     using (var context = new PostgressContext())
     {
         Comments comment = context.Comments.Where(x => x.Id == commId).FirstOrDefault();
         context.Comments.Remove(comment);
         context.SaveChanges();
     }
 }
Exemple #7
0
 public void PatchComm(int commId, Comment comment)
 {
     using (var context = new PostgressContext())
     {
         Comments _comment = context.Comments.Where(x => x.Id == commId).FirstOrDefault();
         _comment.Body   = comment.Body;
         _comment.PostId = comment.Postid;
         _comment.Title  = comment.Title;
         _comment.UserId = comment.Userid;
         context.SaveChanges();
     }
 }
Exemple #8
0
 public int GetRating(int postid)
 {
     using (var context = new PostgressContext())
     {
         int sum         = 0;
         var ratingsList = context.Ratings.Where(x => x.PostId == postid).ToList();
         foreach (var item in ratingsList)
         {
             sum = sum + item.RatingValue;
         }
         return(sum / ratingsList.Count());
     }
 }
Exemple #9
0
 public void PutRating(Models.Front.Rating rating)
 {
     using (var context = new PostgressContext())
     {
         context.Ratings.Add(new Ratings
         {
             RatingValue = rating.RatingValue,
             Date        = DateTime.Now,
             UserId      = rating.UserId,
             PostId      = rating.PostId
         }
                             );
         context.SaveChanges();
     }
 }
Exemple #10
0
        public void PutComm(Comment comment)
        {
            using (var context = new PostgressContext())
            {
                context.Comments.Add(new Comments
                {
                    Body   = comment.Body,
                    Title  = comment.Title,
                    UserId = comment.Userid,
                    PostId = comment.Postid
                }
                                     );

                context.SaveChanges();
            }
        }
Exemple #11
0
        public void CreatePost(Post post)
        {
            using (var context = new PostgressContext())
            {
                context.Posts.Add(new Postss()
                {
                    Title       = post.Title,
                    Body        = post.Body,
                    Description = post.Description,
                    CategoryId  = post.CategoryId,
                    Date        = DateTime.Now,
                    UserId      = post.UserId
                }
                                  );

                context.SaveChanges();
            }
        }