//GET ALBUM LIST FOR LABEL OR ARTIST public List <SongGetModel> GetSongsAlbum(string albumId) { List <SongGetModel> songGetModels = new List <SongGetModel>(); var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("AlbumId", albumId); var results = collection.Find(filter).ToList(); foreach (BsonDocument result in results) { if (result != null) { SongGetModel songGetModel = new SongGetModel(); SongGetModel res = BsonSerializer.Deserialize <SongGetModel>(result); songGetModel.SongId = res.SongId; songGetModel.SongName = res.SongName; songGetModel.ArtistName = res.ArtistName; songGetModel.AlbumId = res.AlbumId; songGetModel.Genre = res.Genre; songGetModel.SongFileUrl = res.SongFileUrl; songGetModel.TimesStreamed = res.TimesStreamed; songGetModel.CoverImageUrl = res.CoverImageUrl; songGetModels.Add(songGetModel); } } return(songGetModels); }
public SearchResultModel SearchResult(string query) { SearchResultModel searchResultModel = new SearchResultModel(); searchResultModel.AlbumGetModels = new List <AlbumGetModel>(); searchResultModel.SongGetModels = new List <SongGetModel>(); searchResultModel.ArtistGetInfoModels = new List <ArtistGetInfoModel>(); var songCollection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var artistCollection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("artists"); var albumCollection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("albums"); var songfilter = new BsonDocument { { "SongName", new BsonDocument { { "$regex", query }, { "$options", "i" } } } }; var songResults = songCollection.Find(songfilter).ToList(); var albumfilter = new BsonDocument { { "AlbumName", new BsonDocument { { "$regex", query }, { "$options", "i" } } } }; var albumResults = albumCollection.Find(albumfilter).ToList(); var artistfilter = new BsonDocument { { "FirstName", new BsonDocument { { "$regex", query }, { "$options", "i" } } } }; var artistResults = artistCollection.Find(artistfilter).ToList(); foreach (BsonDocument result in songResults) { if (result != null) { SongGetModel res = BsonSerializer.Deserialize <SongGetModel>(result); searchResultModel.SongGetModels.Add(res); } } foreach (BsonDocument result in albumResults) { if (result != null) { AlbumGetModel res = BsonSerializer.Deserialize <AlbumGetModel>(result); searchResultModel.AlbumGetModels.Add(res); } } foreach (BsonDocument result in artistResults) { if (result != null) { ArtistGetInfoModel res = BsonSerializer.Deserialize <ArtistGetInfoModel>(result); searchResultModel.ArtistGetInfoModels.Add(res); } } return(searchResultModel); }
//ADD SONG PLAYLIST public bool AddSongPlaylist(string userId, string playlistId, string songId) { SongGetModel songGetModel = null; var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("SongId", songId); var result = collection.Find(filter).FirstOrDefault(); if (result != null) { songGetModel = new SongGetModel(); SongGetModel res = BsonSerializer.Deserialize <SongGetModel>(result); songGetModel.SongId = res.SongId; songGetModel.SongName = res.SongName; songGetModel.ArtistName = res.ArtistName; songGetModel.AlbumId = res.AlbumId; songGetModel.Genre = res.Genre; songGetModel.SongFileUrl = res.SongFileUrl; songGetModel.TimesStreamed = res.TimesStreamed; songGetModel.CoverImageUrl = res.CoverImageUrl; } else { return(false); } var collectionPlaylist = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("playlists"); var playlistFilter = Builders <BsonDocument> .Filter.Eq("CreatorId", userId) & Builders <BsonDocument> .Filter.Eq("PlaylistId", playlistId); var update = Builders <BsonDocument> .Update.AddToSet("Songs", new BsonDocument { { "SongId", songGetModel.SongId }, { "SongName", songGetModel.SongName }, { "SongFileUrl", songGetModel.SongFileUrl }, { "AlbumId", songGetModel.AlbumId }, { "ArtistName", songGetModel.ArtistName }, { "TimesStreamed", songGetModel.TimesStreamed }, { "Genre", songGetModel.Genre }, { "CoverImageUrl", songGetModel.CoverImageUrl } }); if (collectionPlaylist.UpdateOne(playlistFilter, update).ModifiedCount > 0) { return(true); } return(false); }
public GlobalTopModel GetGlobalTop(string id) { GlobalTopModel globalTopModel = new GlobalTopModel(); globalTopModel.SongGetModels = new List <SongGetModel>(); var songCollection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var songResults = songCollection.Find(new BsonDocument()).Limit(50).ToList(); foreach (BsonDocument result in songResults) { if (result != null) { SongGetModel res = BsonSerializer.Deserialize <SongGetModel>(result); globalTopModel.SongGetModels.Add(res); } } return(globalTopModel); }
public RecommendedModel GetRecommended(string id) { RecommendedModel recommendedModel = new RecommendedModel(); recommendedModel.AlbumGetModels = new List <AlbumGetModel>(); recommendedModel.SongGetModels = new List <SongGetModel>(); recommendedModel.ArtistGetInfoModels = new List <ArtistGetInfoModel>(); var songCollection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var artistCollection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("artists"); var albumCollection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("albums"); var songResults = songCollection.Find(new BsonDocument()).Limit(15).ToList(); var albumResults = albumCollection.Find(new BsonDocument()).Limit(15).ToList(); var artistResults = artistCollection.Find(new BsonDocument()).Limit(15).ToList(); foreach (BsonDocument result in songResults) { if (result != null) { SongGetModel res = BsonSerializer.Deserialize <SongGetModel>(result); recommendedModel.SongGetModels.Add(res); } } foreach (BsonDocument result in albumResults) { if (result != null) { AlbumGetModel res = BsonSerializer.Deserialize <AlbumGetModel>(result); recommendedModel.AlbumGetModels.Add(res); } } foreach (BsonDocument result in artistResults) { if (result != null) { ArtistGetInfoModel res = BsonSerializer.Deserialize <ArtistGetInfoModel>(result); recommendedModel.ArtistGetInfoModels.Add(res); } } return(recommendedModel); }
//GET SONG BY ALBUM ID public SongGetModel GetSong(string id) { SongGetModel songGetModel = null; var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("SongId", id); var result = collection.Find(filter).FirstOrDefault(); if (result != null) { songGetModel = new SongGetModel(); SongGetModel res = BsonSerializer.Deserialize <SongGetModel>(result); songGetModel.SongId = res.SongId; songGetModel.SongName = res.SongName; songGetModel.ArtistName = res.ArtistName; songGetModel.AlbumId = res.AlbumId; songGetModel.Genre = res.Genre; songGetModel.SongFileUrl = res.SongFileUrl; songGetModel.TimesStreamed = res.TimesStreamed; songGetModel.CoverImageUrl = res.CoverImageUrl; } return(songGetModel); }