using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using SkyArtShop.Models; using SkyArtShop.Services; namespace SkyArtShop.Controllers; public class PortfolioController : Controller { private readonly PostgreSQLService _pgService; private readonly string _categoriesCollection = "PortfolioCategories"; private readonly string _projectsCollection = "PortfolioProjects"; public PortfolioController(PostgreSQLService pgService) { _pgService = pgService; } public async Task Index() { List model = (from c in await _pgService.GetAllAsync(_categoriesCollection) where c.IsActive orderby c.DisplayOrder select c).ToList(); return View(model); } public async Task Category(string slug) { PortfolioCategory category = (await _pgService.GetAllAsync(_categoriesCollection)).FirstOrDefault((PortfolioCategory c) => c.Slug == slug && c.IsActive); if (category == null) { return NotFound(); } List model = (from p in await _pgService.GetAllAsync(_projectsCollection) where p.CategoryId == category.Id && p.IsActive orderby p.DisplayOrder select p).ToList(); base.ViewBag.Category = category; return View(model); } public async Task Project(string id) { PortfolioProject portfolioProject = await _pgService.GetByIdAsync(_projectsCollection, id); if (portfolioProject == null) { return NotFound(); } return View(portfolioProject); } }