public Postss Post(int postId) { using (var context = new PostgressContext()) { return(context.Posts.FirstOrDefault(x => x.Id == postId)); } }
public List <Categories> Categories() { using (var context = new PostgressContext()) { return(context.Categories.ToList()); } }
public List <Users> Users() { using (var context = new PostgressContext()) { return(context.Users.ToList()); } }
public List <Comments> CommentsToPost(int postId) { using (var context = new PostgressContext()) { return(context.Comments.Where(x => x.PostId == postId).ToList()); } }
public List <Postss> Posts() { using (var context = new PostgressContext()) { return(context.Posts.ToList()); } }
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(); } }
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(); } }
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()); } }
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(); } }
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(); } }
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(); } }