示例#1
0
        public IActionResult Artist(string id)
        {
            JObject artist = new JObject();

            ApiCaller.GetArtistData(id, a => {
                artist = (JObject)a;
            }).Wait();
            ViewBag.artist = artist;
            List <DisplayRelease> releases = new List <DisplayRelease>();
            JToken temp = artist.SelectToken("release-groups");

            foreach (var release in temp)
            {
                DisplayRelease toAdd = new DisplayRelease()
                {
                    id    = (string)release["id"],
                    title = (string)release["title"],
                    date  = (string)release["first-release-date"]
                };
                if ((string)release["primary-type"] == "Album" && release["secondary-types"].Count() == 0)
                {
                    toAdd.type = "Album";
                }
                if ((string)release["primary-type"] == "EP" && release["secondary-types"].Count() == 0)
                {
                    toAdd.type = "EP";
                }
                if (release["secondary-types"].Count() > 0)
                {
                    if ((string)release["secondary-types"].First == "Live" || (string)release["secondary-types"].Last() == "Live")
                    {
                        toAdd.type = "Live";
                    }
                }
                releases.Add(toAdd);
            }
            ViewBag.albums = releases.Where(r => r.type == "Album").OrderBy(r => r.date).ToList();
            ViewBag.eps    = releases.Where(r => r.type == "EP").OrderBy(r => r.date).ToList();
            ViewBag.live   = releases.Where(r => r.type == "Live").OrderBy(r => r.date).ToList();
            return(View());
        }