//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); }
//UPDATE USER DATA public bool UpdateArtist(ArtistUpdateModel artistUpdateModel) { if (artistUpdateModel.ProfileImage != null) { artistUpdateModel.ProfileImageUrl = UploadProfileImage(artistUpdateModel.ProfileImage, artistUpdateModel.Id); } else { artistUpdateModel.ProfileImageUrl = null; } var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("artists"); var filter = Builders <BsonDocument> .Filter.Eq("ArtistId", artistUpdateModel.Id); var update = Builders <BsonDocument> .Update.Set("ArtistId", artistUpdateModel.Id); foreach (PropertyInfo prop in artistUpdateModel.GetType().GetProperties()) { var value = artistUpdateModel.GetType().GetProperty(prop.Name).GetValue(artistUpdateModel, null); if ((prop.Name != "Id") && (prop.Name != "JwtToken") && (prop.Name != "ProfileImage")) { if (value != null) { update = update.Set(prop.Name, value); } } } if (collection.UpdateOne(filter, update).ModifiedCount > 0) { return(true); } return(false); }
//GET USER DATA public List <ArtistGetInfoModel> GetAllArtistInfo(string labelId) { List <ArtistGetInfoModel> artistGetInfoModels = new List <ArtistGetInfoModel>(); var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("artists"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("LabelId", labelId); var results = collection.Find(filter).ToList(); foreach (BsonDocument result in results) { if (result != null) { ArtistGetInfoModel res = BsonSerializer.Deserialize <ArtistGetInfoModel>(result); //MysqlConnectionProvider dbConnection = new MysqlConnectionProvider(); //dbConnection.CreateQuery("SELECT username,email,phone FROM users WHERE id='" + res.ArtistId + "'"); //MySqlDataReader reader = dbConnection.DoQuery(); //while (reader.Read()) //{ // res.Username = reader["username"].ToString(); // res.Email = reader["email"].ToString(); // res.Phone = reader["phone"].ToString(); //} //dbConnection.Dispose(); //dbConnection = null; artistGetInfoModels.Add(res); } } return(artistGetInfoModels); }
public bool UpdateLabel(LabelUpdateModel labelUpdateModel) { if (labelUpdateModel.LabelIcon != null) { labelUpdateModel.LabelIconUrl = UploadLabelIcon(labelUpdateModel.LabelIcon, labelUpdateModel.Id); } else { labelUpdateModel.LabelIconUrl = null; } var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("labels"); var filter = Builders <BsonDocument> .Filter.Eq("LabelId", labelUpdateModel.Id); var update = Builders <BsonDocument> .Update.Set("LabelId", labelUpdateModel.Id); foreach (PropertyInfo prop in labelUpdateModel.GetType().GetProperties()) { var value = labelUpdateModel.GetType().GetProperty(prop.Name).GetValue(labelUpdateModel, null); if ((prop.Name != "Id") && (prop.Name != "JwtToken") && (prop.Name != "LabelIcon")) { if (value != null) { update = update.Set(prop.Name, value); } } } if (collection.UpdateOne(filter, update).ModifiedCount > 0) { return(true); } return(false); }
//GET ALBUM LIST FOR LABEL OR ARTIST public List <AlbumGetModel> GetAlbumList(string id) { List <AlbumGetModel> albumGetModels = new List <AlbumGetModel>(); var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("albums"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("LabelId", id) | builder.Eq("ArtistId", id); var results = collection.Find(filter).ToList(); foreach (BsonDocument result in results) { if (result != null) { AlbumGetModel albumGetModel = new AlbumGetModel(); AlbumGetModel res = BsonSerializer.Deserialize <AlbumGetModel>(result); albumGetModel.AlbumId = res.AlbumId; albumGetModel.AlbumName = res.AlbumName; albumGetModel.CoverImageUrl = res.CoverImageUrl; albumGetModel.Year = res.Year; albumGetModel.Genre = res.Genre; albumGetModel.ArtistId = res.ArtistId; albumGetModel.LabelId = res.LabelId; albumGetModels.Add(albumGetModel); } } return(albumGetModels); }
//UPDATE PLAYLIST public bool UpdatePlaylist(PlaylistCreateModel playlistCreateModel) { if (playlistCreateModel.PlaylistImage != null) { playlistCreateModel.PlaylistImageUrl = UploadPlaylistCoverImage(playlistCreateModel.PlaylistImage, playlistCreateModel.PlaylistId); } else { playlistCreateModel.PlaylistImageUrl = UploadPlaylistCoverImage(new DynamicPictureGenerator().GenerateNewImage(playlistCreateModel.PlaylistName[0].ToString(), 854, 854, 500), playlistCreateModel.PlaylistId); } var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("playlists"); var filter = Builders <BsonDocument> .Filter.Eq("PlaylistId", playlistCreateModel.PlaylistId); var update = Builders <BsonDocument> .Update.Set("PlaylistId", playlistCreateModel.PlaylistId); foreach (PropertyInfo prop in playlistCreateModel.GetType().GetProperties()) { var value = playlistCreateModel.GetType().GetProperty(prop.Name).GetValue(playlistCreateModel, null); if ((prop.Name != "PlaylistId") && (prop.Name != "JwtToken") && (prop.Name != "PlaylistImage")) { if (value != null) { update = update.Set(prop.Name, value); } } } if (collection.UpdateOne(filter, update).ModifiedCount > 0) { return(true); } return(false); }
public ListenerGetInfoModel GetListenerInfo(string Id) { MysqlConnectionProvider dbConnection = new MysqlConnectionProvider(); dbConnection.CreateQuery("SELECT username,email,phone FROM users WHERE id='" + Id + "'"); ListenerGetInfoModel listenerGetInfoModel = null; MySqlDataReader reader = dbConnection.DoQuery(); while (reader.Read()) { listenerGetInfoModel = new ListenerGetInfoModel(); listenerGetInfoModel.Username = reader["username"].ToString(); listenerGetInfoModel.Email = reader["email"].ToString(); listenerGetInfoModel.Phone = reader["phone"].ToString(); } dbConnection.Dispose(); dbConnection = null; var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("listeners"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("ListenerId", Id); var result = collection.Find(filter).FirstOrDefault(); if (result != null) { ListenerGetInfoModel res = BsonSerializer.Deserialize <ListenerGetInfoModel>(result); listenerGetInfoModel.ListenerId = res.ListenerId; listenerGetInfoModel.ProfileImageUrl = res.ProfileImageUrl; listenerGetInfoModel.FirstName = res.FirstName; listenerGetInfoModel.LastName = res.LastName; listenerGetInfoModel.Dob = res.Dob; listenerGetInfoModel.Region = res.Region; listenerGetInfoModel.IsSubscriber = res.IsSubscriber; } return(listenerGetInfoModel); }
//GET ALL PLAYLIST public List <PlaylistGetModel> GetAllPlaylist(string creatorId) { List <PlaylistGetModel> playlistGetModels = new List <PlaylistGetModel>(); var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("playlists"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("CreatorId", creatorId); var results = collection.Find(filter).ToList(); int i = 0; foreach (BsonDocument result in results) { if (result != null) { playlistGetModels.Add(BsonSerializer.Deserialize <PlaylistGetModel>(result)); playlistGetModels.ElementAt(i).SongGetModels = new List <SongGetModel>(); foreach (BsonDocument res in result.GetValue("Songs").AsBsonArray) { if (res != null) { playlistGetModels.ElementAt(i).SongGetModels.Add(BsonSerializer.Deserialize <SongGetModel>(res)); } } } i++; } return(playlistGetModels); }
//INSERT ALBUM public bool CreatePlaylist(PlaylistCreateModel playlistCreateModel) { if (playlistCreateModel.PlaylistImage != null) { playlistCreateModel.PlaylistImageUrl = UploadPlaylistCoverImage(playlistCreateModel.PlaylistImage, playlistCreateModel.PlaylistId); } else { playlistCreateModel.PlaylistImageUrl = UploadPlaylistCoverImage(new DynamicPictureGenerator().GenerateNewImage(playlistCreateModel.PlaylistName[0].ToString(), 854, 854, 500), playlistCreateModel.PlaylistId); } try { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("playlists"); var document = new BsonDocument { { "PlaylistId", playlistCreateModel.PlaylistId }, { "PlaylistName", playlistCreateModel.PlaylistName }, { "PlaylistImageUrl", playlistCreateModel.PlaylistImageUrl }, { "CreatorId", playlistCreateModel.CreatorId }, { "Songs", new BsonArray() } }; collection.InsertOne(document); return(true); } catch (Exception) { return(false); } }
public LabelGetInfoModel GetLabelInfo(string Id) { MysqlConnectionProvider dbConnection = new MysqlConnectionProvider(); dbConnection.CreateQuery("SELECT username,email,phone FROM users WHERE id='" + Id + "'"); LabelGetInfoModel labelGetInfoModel = null; MySqlDataReader reader = dbConnection.DoQuery(); while (reader.Read()) { labelGetInfoModel = new LabelGetInfoModel(); labelGetInfoModel.Username = reader["username"].ToString(); labelGetInfoModel.Email = reader["email"].ToString(); labelGetInfoModel.Phone = reader["phone"].ToString(); } dbConnection.Dispose(); dbConnection = null; var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("labels"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("LabelId", Id); var result = collection.Find(filter).FirstOrDefault(); if (result != null) { LabelGetInfoModel res = BsonSerializer.Deserialize <LabelGetInfoModel>(result); labelGetInfoModel.LabelId = res.LabelId; labelGetInfoModel.LabelIconUrl = res.LabelIconUrl; labelGetInfoModel.LabelName = res.LabelName; labelGetInfoModel.EstDate = res.EstDate; labelGetInfoModel.IsVerified = res.IsVerified; labelGetInfoModel.Region = res.Region; } return(labelGetInfoModel); }
//UPDATE SONG public bool UpdateSong(SongUpdateModel songUpdateModel) { if (songUpdateModel.SongFile != null) { songUpdateModel.SongFileUrl = UploadAudioFile(songUpdateModel.SongFile, songUpdateModel.SongId); } else { songUpdateModel.SongFileUrl = null; } var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var filter = Builders <BsonDocument> .Filter.Eq("SongId", songUpdateModel.SongId); var update = Builders <BsonDocument> .Update.Set("SongId", songUpdateModel.SongId); foreach (PropertyInfo prop in songUpdateModel.GetType().GetProperties()) { var value = songUpdateModel.GetType().GetProperty(prop.Name).GetValue(songUpdateModel, null); if ((prop.Name != "SongId") && (prop.Name != "JwtToken") && (prop.Name != "SongFile") && (prop.Name != "CoverImage")) { if (value != null) { update = update.Set(prop.Name, value); } } } if (collection.UpdateOne(filter, update).ModifiedCount > 0) { return(true); } return(false); }
//REMOVE SONG PLAYLIST public bool RemoveSongPlaylist(string userId, string playlistId, string songId) { 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.PullFilter("Songs", Builders <BsonDocument> .Filter.Eq("SongId", songId)); return(collectionPlaylist.UpdateOne(playlistFilter, update).ModifiedCount > 0); }
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); }
//DELETE ALBUM public bool DeleteAlbum(string labelId, string albumId) { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("albums"); var deleteFilter = Builders <BsonDocument> .Filter.Eq("AlbumId", albumId) & Builders <BsonDocument> .Filter.Eq("LabelId", labelId); if (collection.DeleteOne(deleteFilter).DeletedCount > 0) { return(true); } return(false); }
//DELETE ALBUM public bool DeletePlaylist(string userId, string playlistId) { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("playlists"); var deleteFilter = Builders <BsonDocument> .Filter.Eq("CreatorId", userId) & Builders <BsonDocument> .Filter.Eq("PlaylistId", playlistId); if (collection.DeleteOne(deleteFilter).DeletedCount > 0) { return(true); } return(false); }
//DELETE ALBUM public bool DeleteSong(string songId) { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var deleteFilter = Builders <BsonDocument> .Filter.Eq("SongId", songId); if (collection.DeleteOne(deleteFilter).DeletedCount > 0) { return(true); } return(false); }
//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); }
//GET PLAYLIST public PlaylistGetModel GetPlaylist(string playlistId) { PlaylistGetModel playlistGetModel = null; var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("playlists"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("PlaylistId", playlistId); var result = collection.Find(filter).FirstOrDefault(); if (result != null) { playlistGetModel = BsonSerializer.Deserialize <PlaylistGetModel>(result); playlistGetModel.SongGetModels = new List <SongGetModel>(); foreach (BsonDocument res in result.GetValue("Songs").AsBsonArray) { playlistGetModel.SongGetModels.Add(BsonSerializer.Deserialize <SongGetModel>(res)); } } return(playlistGetModel); }
//ARTIST REGISTRATION public bool RegisterArtist(ArtistGlobalModel artist) { bool InsertArtistMysql() { MysqlConnectionProvider dbConnection = new MysqlConnectionProvider(); dbConnection.CreateQuery("INSERT INTO users(id, username, email, phone, pass, type, isemailverified) VALUES ('" + artist.Id + "','" + artist.Username + "','" + artist.Email + "','" + artist.Phone + "','" + artist.Pass + "','" + artist.Type + "','" + artist.IsEmailVerified + "')"); if ((dbConnection.DoNoQuery()) < 1) { dbConnection.Dispose(); return(false); } dbConnection.Dispose(); return(true); } bool InsertArtistMongo() { try { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("artists"); var document = new BsonDocument { { "ArtistId", artist.Id }, { "ProfileImageUrl", artist.ProfileImageUrl }, { "FirstName", artist.FirstName }, { "LastName", artist.LastName }, { "Dob", artist.Dob }, { "Region", artist.Region }, { "LabelId", artist.LabelId }, { "IsVerified", artist.IsVerified } }; collection.InsertOne(document); return(true); } catch (Exception) { return(false); } } return(InsertArtistMysql() && InsertArtistMongo()); }
//LISTENER REGISTRATION public bool RegisterListener(ListenerGlobalModel listener) { bool InsertListenerMysql() { MysqlConnectionProvider dbConnection = new MysqlConnectionProvider(); dbConnection.CreateQuery("INSERT INTO users(id, username, email, phone, pass, type, isemailverified) VALUES ('" + listener.Id + "','" + listener.Username + "','" + listener.Email + "','" + listener.Phone + "','" + listener.Pass + "','" + listener.Type + "','" + listener.IsEmailVerified + "')"); if ((dbConnection.DoNoQuery()) < 1) { dbConnection.Dispose(); return(false); } dbConnection.Dispose(); return(true); } bool InsertListenerMongo() { try { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("listeners"); var document = new BsonDocument { { "ListenerId", listener.Id }, { "ProfileImageUrl", listener.ProfileImageUrl }, { "FirstName", listener.FirstName }, { "LastName", listener.LastName }, { "Dob", listener.Dob }, { "Region", listener.Region }, { "IsSubscriber", listener.IsSubscriber } }; collection.InsertOne(document); return(true); } catch (Exception) { return(false); } } return(InsertListenerMysql() && InsertListenerMongo()); }
//LABEL REGISTRTION public bool RegisterLabel(LabelGlobalModel label) { bool InsertLabelMysql() { MysqlConnectionProvider dbConnection = new MysqlConnectionProvider(); dbConnection.CreateQuery("INSERT INTO users(id, username, email, phone, pass, type, isemailverified) VALUES ('" + label.Id + "','" + label.Username + "','" + label.Email + "','" + label.Phone + "','" + label.Pass + "','" + label.Type + "','" + label.IsEmailVerified + "')"); if ((dbConnection.DoNoQuery()) < 1) { dbConnection.Dispose(); return(false); } dbConnection.Dispose(); return(true); } bool InsertLabelMongo() { try { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("labels"); var document = new BsonDocument { { "LabelId", label.Id }, { "LabelIconUrl", label.LabelIconUrl }, { "LabelName", label.LabelName }, { "EstDate", label.EstDate }, { "Region", label.Region }, { "IsVerified", label.IsVerified } }; collection.InsertOne(document); return(true); } catch (Exception) { return(false); } } return(InsertLabelMysql() && InsertLabelMongo()); }
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 ALBUM BY ALBUM ID public AlbumGetModel GetAlbum(string id) { AlbumGetModel albumGetModel = null; var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("albums"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("AlbumId", id); var result = collection.Find(filter).FirstOrDefault(); if (result != null) { albumGetModel = new AlbumGetModel(); AlbumGetModel res = BsonSerializer.Deserialize <AlbumGetModel>(result); albumGetModel.AlbumId = res.AlbumId; albumGetModel.AlbumName = res.AlbumName; albumGetModel.CoverImageUrl = res.CoverImageUrl; albumGetModel.Year = res.Year; albumGetModel.Genre = res.Genre; albumGetModel.ArtistId = res.ArtistId; albumGetModel.LabelId = res.LabelId; } return(albumGetModel); }
//INSERT ALBUM public bool CreateAlbum(AlbumGlobalModel albumGlobalModel) { try { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("albums"); var document = new BsonDocument { { "AlbumId", albumGlobalModel.Id }, { "AlbumName", albumGlobalModel.AlbumName }, { "CoverImageUrl", albumGlobalModel.CoverImageUrl }, { "LabelId", albumGlobalModel.LabelId }, { "ArtistId", albumGlobalModel.ArtistId }, { "Year", albumGlobalModel.Year }, { "Genre", albumGlobalModel.Genre } }; collection.InsertOne(document); return(true); } catch (Exception) { return(false); } }
//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); }
public ArtistGetInfoModel GetArtistInfo(string Id) { MysqlConnectionProvider dbConnection = new MysqlConnectionProvider(); dbConnection.CreateQuery("SELECT username,email,phone FROM users WHERE id='" + Id + "'"); ArtistGetInfoModel artistGetInfoModel = null; MySqlDataReader reader = dbConnection.DoQuery(); while (reader.Read()) { artistGetInfoModel = new ArtistGetInfoModel(); artistGetInfoModel.Username = reader["username"].ToString(); artistGetInfoModel.Email = reader["email"].ToString(); artistGetInfoModel.Phone = reader["phone"].ToString(); } dbConnection.Dispose(); dbConnection = null; var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("artists"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("ArtistId", Id); var result = collection.Find(filter).FirstOrDefault(); if (result != null) { ArtistGetInfoModel res = BsonSerializer.Deserialize <ArtistGetInfoModel>(result); artistGetInfoModel.ArtistId = res.ArtistId; artistGetInfoModel.ProfileImageUrl = res.ProfileImageUrl; artistGetInfoModel.FirstName = res.FirstName; artistGetInfoModel.LastName = res.LastName; artistGetInfoModel.Dob = res.Dob; artistGetInfoModel.Region = res.Region; artistGetInfoModel.IsVerified = res.IsVerified; artistGetInfoModel.LabelId = res.LabelId; } return(artistGetInfoModel); }
//UPLOAD SONG public bool UploadSong(SongGlobalModel songGlobalModel) { try { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var document = new BsonDocument { { "SongId", songGlobalModel.Id }, { "SongName", songGlobalModel.SongName }, { "SongFileUrl", songGlobalModel.SongFileUrl }, { "AlbumId", songGlobalModel.AlbumId }, { "ArtistName", songGlobalModel.ArtistName }, { "TimesStreamed", songGlobalModel.TimesStreamed }, { "Genre", songGlobalModel.Genre }, { "CoverImageUrl", songGlobalModel.CoverImageUrl } }; collection.InsertOne(document); return(true); } catch (Exception) { return(false); } }