﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PHBGTU.Data;
using PHBGTU.Models;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PHBGTU.ViewComponents
{
    public class NewsletterViewComponent: ViewComponent
    {
        private readonly ApplicationDbContext _context;//database

        public NewsletterViewComponent(ApplicationDbContext context)
        {
            _context = context;
        }

        public async Task<IViewComponentResult> InvokeAsync(int blockId)
        {
            var contentBlock = await GetBlockAsync(blockId);            
            return View(contentBlock);
        }

        private async Task<List<ContentBlock>> GetBlockAsync(int blockId)
        {
            return await _context.ContentBlocks.Where(m => m.ContentBlockId == blockId).ToListAsync();           
        }
    }
}
