using TechTitans.Models; using TechTitans.Repositories; namespace TechTitans.Services { public class ArtistSongDashboardController { private Repository SongRepo = new Repository(); private Repository FeatureRepo = new Repository(); private Repository SongRecommendationRepo = new Repository(); private Repository ArtistRepo = new Repository(); //converts song details to song info public SongBasicInfo songBasicDetailsToInfo(SongBasicDetails song) { SongBasicInfo songInfo = new SongBasicInfo(); songInfo.SongId = song.Song_Id; songInfo.Name = song.Name; songInfo.Genre = song.Genre; songInfo.Subgenre = song.Subgenre; songInfo.Language = song.Language; songInfo.Country = song.Country; songInfo.Album = song.Album; songInfo.Image = song.Image; foreach (AuthorDetails artist in ArtistRepo.GetAll()) { if (artist.Artist_Id == song.Artist_Id) { songInfo.Artist = artist.Name; } } foreach (SongFeatures feature in FeatureRepo.GetAll()) { if (feature.Song_Id == song.Song_Id) { songInfo.Features.Add(feature.ToString()); } } return songInfo; } //get all artist's publish song (returns List) public List getAllArtistSongs(int artistId) { List artistSongs = new List(); foreach (SongBasicDetails song in SongRepo.GetAll()) { if (song.Artist_Id == artistId) { SongBasicInfo songInfo = songBasicDetailsToInfo(song); artistSongs.Add(songInfo); } } return artistSongs; } //search by string in titles (returns list of songs, case insensitive) public List searchByTitle(string title) { List songs = new List(); foreach (SongBasicDetails song in SongRepo.GetAll()) { if (song.Name.ToLower().Trim().Contains(title.ToLower())) { SongBasicInfo songInfo = songBasicDetailsToInfo(song); songs.Add(songInfo); } } return songs; } //gets song info by song id public SongBasicInfo getSongInfo(int songId) { foreach (SongBasicDetails song in SongRepo.GetAll()) { if (song.Song_Id == songId) { SongBasicInfo songInfo = songBasicDetailsToInfo(song); return songInfo; } } return null; } //gets song recommendation details by song id public SongRecommendationDetails getSongDetails(int songId) { foreach (SongRecommendationDetails songDetails in SongRecommendationRepo.GetAll()) { if (songDetails.Song_Id == songId) { return songDetails; } } return new SongRecommendationDetails(); } //gets artist info by song id public AuthorDetails getArtistInfo(int SongId) { foreach (SongBasicDetails song in SongRepo.GetAll()) { if (song.Song_Id == SongId) { foreach (AuthorDetails artist in ArtistRepo.GetAll()) { if (artist.Artist_Id == song.Artist_Id) { return artist; } } } } return null; } public AuthorDetails getMostPublishedAuthor() { Dictionary artistCount = new Dictionary(); foreach (SongBasicDetails song in SongRepo.GetAll()) { if (artistCount.ContainsKey(song.Artist_Id)) { artistCount[song.Artist_Id]++; } else { artistCount.Add(song.Artist_Id, 1); } } int max = 0; int artistId = 0; foreach (KeyValuePair entry in artistCount) { if (entry.Value > max) { max = entry.Value; artistId = entry.Key; } } foreach (AuthorDetails artist in ArtistRepo.GetAll()) { if (artist.Artist_Id == artistId) { return artist; } } return null; } public List getSongsForMainPage() { List songs = new List(); int artistId = getMostPublishedAuthor().Artist_Id; foreach (SongBasicDetails song in SongRepo.GetAll()) { if (song.Artist_Id == artistId) { SongBasicInfo songInfo = songBasicDetailsToInfo(song); songs.Add(songInfo); } } return songs; } } }