SAB-E02/Blog.DAL/Repository/CommentRepository.cs
2021-04-06 18:04:43 +02:00

33 lines
681 B
C#

using System.Collections.Generic;
using Blog.DAL.Infrastructure;
using Blog.DAL.Model;
using System;
using System.Linq;
namespace Blog.DAL.Repository
{
public class CommentRepository
{
private readonly BlogContext _context;
public CommentRepository()
{
_context = new BlogContext();
}
public IEnumerable<Comment> GetAllCommentsOf(long postId)
{
return _context.Comments.Where(c => c.PostId == postId);
}
public Comment add(Comment comment)
{
_context.Comments.Add(comment);
_context.SaveChanges();
return comment;
}
}
}