Example #1
0
        public ActionResult EditarCancion(int Id)
        {
            try
            {
                Songs song = new Songs();
                song = new Front().BuscarCancion(Id);
                Models.Songs sog = new Models.Songs();
                sog.id   = song.id;
                sog.Name = song.Name;

                List <Album> alb = new List <Album>();
                alb = new Front().ListarAlbum();

                List <SelectListItem> items = alb.ConvertAll(al =>
                {
                    return(new SelectListItem()
                    {
                        Text = al.Name,
                        Value = Convert.ToString(al.id),
                        Selected = true
                    });
                });

                ViewBag.items = items;
                return(View(sog));
            }
            catch (Exception e)
            {
                Request.Flash("danger", e.Message);
                throw;
            }
        }
Example #2
0
        public async Task <List <Models.Songs> > GetArtistsSongs(string Id, string token)
        {
            List <Models.Songs> topSongs = new List <Models.Songs>();
            HttpClient          client   = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            string url = "https://api.spotify.com/v1/artists/" + Id + "/top-tracks";

            client.BaseAddress = new Uri(url);
            string urlParameters         = "?country=US";
            HttpResponseMessage response = client.GetAsync(urlParameters).Result;

            if (response.IsSuccessStatusCode)
            {
                var     result      = response.Content.ReadAsStringAsync().Result;
                string  replacement = System.Text.RegularExpressions.Regex.Replace(result, @"\t|\n|\r|\\\\", "");
                JObject s           = JObject.Parse(replacement);

                JArray tracks = (JArray)s["tracks"];

                List <Album> albums = tracks.ToObject <List <Album> >();

                if (albums.Count > 0 && albums != null)
                {
                    foreach (var song in albums)
                    {
                        Models.Songs adding = new Models.Songs();
                        adding.SongTitle     = song.name;
                        adding.SongSpotifyId = song.id;
                        StringBuilder arts      = new StringBuilder();
                        int           artsCount = song.artists.Count;
                        int           counter   = 0;
                        foreach (var artist in song.artists)
                        {
                            counter++;
                            arts.Append(artist.name);
                            if (artsCount == counter)
                            {
                            }
                            else
                            {
                                arts.Append(" / ");
                            }
                        }
                        adding.SongArtist = arts.ToString();
                        if (song.images != null && song.images.Count > 0)
                        {
                            string imageWanted = song.images[0].ToString();
                            Image  imageing    = JsonConvert.DeserializeObject <Image>(imageWanted);
                            adding.SongImageUrl = imageing.Url;
                        }

                        topSongs.Add(adding);
                    }
                }
            }

            return(topSongs);
        }
        public int AddSong(Models.Songs song)
        {
            int result = 0;

            try
            {
                result = repo.AddSong(song.SongName, song.DateOfRelease, song.AverageRating, song.ImageCoverLocation);
            }
            catch (Exception)
            {
                result = -99;
            }
            return(result);
        }
Example #4
0
 public ActionResult EditarCancion(Models.Songs song)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     try
     {
         Songs songs = new Songs();
         songs.id       = song.id;
         songs.Name     = song.Name;
         songs.Album_id = song.Album_id;
         new Front().EditarCancion(songs);
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         Request.Flash("danger", e.Message);
         throw;
     }
 }
Example #5
0
        // GET: Song's List
        public ActionResult Index()
        {
            try
            {
                List <Songs> songs = new List <Songs>();
                songs = new Front().ListarCanciones();

                List <Models.Songs> Song = new List <Models.Songs>();
                foreach (Songs song in songs)
                {
                    Models.Songs sgs = new  Models.Songs();
                    sgs.id       = song.id;
                    sgs.Name     = song.Name;
                    sgs.Album_id = song.Album_id;
                    Song.Add(sgs);
                }
                return(View(Song));
            }
            catch (Exception e)
            {
                Request.Flash("danger", e.Message);
                throw;
            }
        }