| [08aefc6] | 1 | using Microsoft.AspNetCore.Mvc;
|
|---|
| 2 | using Microsoft.EntityFrameworkCore;
|
|---|
| 3 | using KernelRecordsMVC.Data;
|
|---|
| 4 |
|
|---|
| 5 | namespace KernelRecordsMVC.Controllers;
|
|---|
| 6 |
|
|---|
| 7 | public class ReleaseController : Controller
|
|---|
| 8 | {
|
|---|
| 9 | private readonly KernelRecordsContext _context;
|
|---|
| 10 |
|
|---|
| 11 | public ReleaseController(KernelRecordsContext context)
|
|---|
| 12 | {
|
|---|
| 13 | _context = context;
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | // UC003 - Browse Releases
|
|---|
| 17 | public IActionResult Index(string? search, string? genre)
|
|---|
| 18 | {
|
|---|
| 19 | var query = _context.Releases
|
|---|
| 20 | .Include(r => r.Products)
|
|---|
| 21 | .Include(r => r.ReleaseArtists)
|
|---|
| 22 | .ThenInclude(ra => ra.Artist)
|
|---|
| 23 | .AsQueryable();
|
|---|
| 24 |
|
|---|
| 25 | if (!string.IsNullOrWhiteSpace(search))
|
|---|
| 26 | {
|
|---|
| 27 | query = query.Where(r =>
|
|---|
| 28 | r.Title.ToLower().Contains(search.ToLower()));
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | if (!string.IsNullOrWhiteSpace(genre))
|
|---|
| 32 | {
|
|---|
| 33 | query = query.Where(r =>
|
|---|
| 34 | r.Genre.ToLower() == genre.ToLower());
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | var releases = query
|
|---|
| 38 | .OrderBy(r => r.Title)
|
|---|
| 39 | .ToList();
|
|---|
| 40 |
|
|---|
| 41 | ViewBag.Search = search;
|
|---|
| 42 | ViewBag.Genre = genre;
|
|---|
| 43 |
|
|---|
| 44 | ViewBag.Genres = _context.Releases
|
|---|
| 45 | .Select(r => r.Genre)
|
|---|
| 46 | .Distinct()
|
|---|
| 47 | .OrderBy(g => g)
|
|---|
| 48 | .ToList();
|
|---|
| 49 |
|
|---|
| 50 | return View(releases);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | // Release details
|
|---|
| 55 | public IActionResult Details(long id)
|
|---|
| 56 | {
|
|---|
| 57 | var release = _context.Releases
|
|---|
| 58 | .Include(r => r.Products)
|
|---|
| 59 | .Include(r => r.ReleaseArtists)
|
|---|
| 60 | .ThenInclude(ra => ra.Artist)
|
|---|
| 61 | .Include(r => r.Album)
|
|---|
| 62 | .ThenInclude(a => a!.AlbumSongs)
|
|---|
| 63 | .ThenInclude(x => x.Song)
|
|---|
| 64 | .Include(r => r.SingleRelease)
|
|---|
| 65 | .ThenInclude(s => s!.SingleFeatures)
|
|---|
| 66 | .ThenInclude(x => x.Song)
|
|---|
| 67 | .FirstOrDefault(r => r.ReleaseId == id);
|
|---|
| 68 |
|
|---|
| 69 | if (release == null)
|
|---|
| 70 | return NotFound();
|
|---|
| 71 |
|
|---|
| 72 | return View(release);
|
|---|
| 73 | }
|
|---|
| 74 | } |
|---|