Beispiel #1
0
        public void AdicionaMusicaSala(int salaId, MusicaModel musica, string userId)
        {
            SqlDataAccess sql = new SqlDataAccess();

            var parameters = new { URI = musica.URI };

            string uri = sql.LoadData <string, dynamic>("dbo.spExisteMusica", parameters, "WebAPIData").FirstOrDefault();

            if (uri == null)
            {
                var musicaParams = new { MusicaURI = musica.URI, Nome = musica.Nome, Duracao = musica.Duracao_ms, Album = musica.Album, Url_imagem = musica.Url_imagem };

                sql.SaveData <MusicaModel, dynamic>("dbo.spAdicionaMusica", musicaParams, "WebAPIData");

                foreach (string artista in musica.Artistas)
                {
                    var artistaParam = new { MusicaURI = musica.URI, Artista = artista };

                    sql.SaveData <MusicaModel, dynamic>("dbo.spAdicionaArtistaMusica", artistaParam, "WebAPIData");
                }
            }

            var paramSalaId = new { SalaId = salaId };

            var paramsSalaMusicaUser = new { SalaId = salaId, MusicaURI = musica.URI, UserId = userId };

            sql.SaveData <string, dynamic>("dbo.spAdicionaMusicaSala", paramsSalaMusicaUser, "WebAPIData");
        }
Beispiel #2
0
        public MusicaModel GetMusicaByURI(string URI)
        {
            SqlDataAccess sql = new SqlDataAccess();

            var p = new { Uri = URI };

            MusicaModel musica = sql.LoadData <MusicaModel, dynamic>("dbo.spMusicaInfo", p, "WebAPIData").FirstOrDefault();

            musica.Artistas = sql.LoadData <string, dynamic>("dbo.spArtistasMusica", p, "WebAPIData");

            return(musica);
        }
        public List <Result> Itunes(string filtro)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://itunes.apple.com/search?media=music&term=" + filtro);

            MusicaModel musics = new MusicaModel();

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    var objText             = reader.ReadToEnd();

                    musics = (MusicaModel)js.Deserialize(objText, typeof(MusicaModel));
                }
            }

            return(musics.results);
        }
Beispiel #4
0
        //POST: adiciona Musica a Sala
        public HttpResponseMessage PostMusica(int SalaId, MusicaModel musica)
        {
            ErrorReader errorReader = new ErrorReader();

            SalaAccess sala = new SalaAccess();

            string userId = RequestContext.Principal.Identity.GetUserId();

            if (sala.VerficaParticipante(SalaId, userId))
            {
                sala.AdicionaMusicaSala(SalaId, musica, userId);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                var       message = string.Format(errorReader.GetErrorMessage(4));
                HttpError err     = new HttpError(message);
                return(Request.CreateResponse(errorReader.GetError(4), err));
            }
        }