Changeset fa0fbaf for KernelRecordsMVC.Web/Controllers/ReleaseController.cs
- Timestamp:
- 09/01/26 06:11:34 (4 weeks ago)
- Branches:
- main
- Children:
- d2eccb3
- Parents:
- 08aefc6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
KernelRecordsMVC.Web/Controllers/ReleaseController.cs
r08aefc6 rfa0fbaf 1 using Microsoft.AspNetCore.Mvc; 1 using KernelRecordsMVC.Domain.Enums; 2 using KernelRecordsMVC.Infrastructure.Data; 3 using Microsoft.AspNetCore.Mvc; 2 4 using Microsoft.EntityFrameworkCore; 3 using KernelRecordsMVC.Data;4 5 5 namespace KernelRecordsMVC. Controllers;6 namespace KernelRecordsMVC.Web.Controllers; 6 7 7 8 public class ReleaseController : Controller … … 14 15 } 15 16 16 // UC003 - Browse Releases 17 public IActionResult Index(string? search, string? genre) 17 // ========================================================= 18 // BROWSE RELEASES 19 // ========================================================= 20 21 public IActionResult Index( 22 string? search, 23 string? genre, 24 string? format, 25 string? type, 26 string? sort) 18 27 { 19 28 var query = _context.Releases 20 29 .Include(r => r.Products) 21 30 .Include(r => r.ReleaseArtists) 22 .ThenInclude(ra => ra.Artist) 31 .ThenInclude(ra => ra.Artist) 32 .Include(r => r.Album) 33 .Include(r => r.SingleRelease) 23 34 .AsQueryable(); 24 35 36 // SEARCH 25 37 if (!string.IsNullOrWhiteSpace(search)) 26 38 { 39 search = search.Trim(); 40 27 41 query = query.Where(r => 28 r.Title.ToLower().Contains(search.ToLower())); 42 r.Title.ToLower().Contains(search.ToLower()) || 43 r.Genre.ToLower().Contains(search.ToLower()) || 44 r.ReleaseArtists.Any(ra => 45 ra.Artist.ArtistName.ToLower() 46 .Contains(search.ToLower()))); 29 47 } 30 48 49 // GENRE 31 50 if (!string.IsNullOrWhiteSpace(genre)) 32 51 { … … 35 54 } 36 55 37 var releases = query 38 .OrderBy(r => r.Title) 39 .ToList(); 56 // FORMAT 57 if (!string.IsNullOrWhiteSpace(format)) 58 { 59 query = query.Where(r => 60 r.Products.Any(p => 61 p.Format.ToString() == format)); 62 } 63 64 // TYPE 65 if (!string.IsNullOrWhiteSpace(type)) 66 { 67 if (type.Equals("Album", StringComparison.OrdinalIgnoreCase)) 68 { 69 query = query.Where(r => r.Album != null); 70 } 71 else if (type.Equals("Single", StringComparison.OrdinalIgnoreCase)) 72 { 73 query = query.Where(r => r.SingleRelease != null); 74 } 75 } 76 77 // SORT 78 query = sort switch 79 { 80 "titleDesc" => 81 query.OrderByDescending(r => r.Title), 82 83 "newest" => 84 query.OrderByDescending(r => r.ReleaseDate), 85 86 "oldest" => 87 query.OrderBy(r => r.ReleaseDate), 88 89 "format" => 90 query.OrderBy(r => 91 r.Products 92 .Select(p => p.Format.ToString()) 93 .FirstOrDefault()), 94 95 "priceAsc" => 96 query.OrderBy(r => 97 r.Products 98 .Select(p => (decimal?)p.Price) 99 .Min()), 100 101 "priceDesc" => 102 query.OrderByDescending(r => 103 r.Products 104 .Select(p => (decimal?)p.Price) 105 .Max()), 106 107 _ => 108 query.OrderBy(r => r.Title) 109 }; 110 111 var releases = query.ToList(); 40 112 41 113 ViewBag.Search = search; 42 114 ViewBag.Genre = genre; 115 ViewBag.Format = format; 116 ViewBag.Type = type; 117 ViewBag.Sort = sort; 43 118 44 119 ViewBag.Genres = _context.Releases … … 48 123 .ToList(); 49 124 125 ViewBag.Formats = Enum 126 .GetValues<ProductFormat>() 127 .Select(x => x.ToString()) 128 .ToList(); 129 50 130 return View(releases); 51 131 } 52 132 53 133 54 // Release details 134 // ========================================================= 135 // DETAILS 136 // ========================================================= 137 55 138 public IActionResult Details(long id) 56 139 { 57 140 var release = _context.Releases 58 141 .Include(r => r.Products) 142 59 143 .Include(r => r.ReleaseArtists) 60 .ThenInclude(ra => ra.Artist) 144 .ThenInclude(ra => ra.Artist) 145 61 146 .Include(r => r.Album) 62 .ThenInclude(a => a!.AlbumSongs) 63 .ThenInclude(x => x.Song) 147 .ThenInclude(a => a!.AlbumSongs) 148 .ThenInclude(x => x.Song) 149 .ThenInclude(s => s.SongArtists) 150 .ThenInclude(sa => sa.Artist) 151 64 152 .Include(r => r.SingleRelease) 65 .ThenInclude(s => s!.SingleFeatures) 66 .ThenInclude(x => x.Song) 153 67 154 .FirstOrDefault(r => r.ReleaseId == id); 68 155
Note:
See TracChangeset
for help on using the changeset viewer.
