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;
        }
    }
}
