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); }
//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 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 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); }
//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); }
//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); }
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); }
//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); }
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); }
//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); }