Пример #1
0
        public MusicReleaseCollection GetDetails(string asin)
        {
            ReleaseDetailItem      releaseDetail           = null;
            MusicReleaseCollection musicReleaseDetailModel = null;

            if (asin != null)
            {
                try
                {
                    releaseDetail = new ReleaseDetails(_amazonRepo, _itunesRepo).GetReleaseDetailsFromASIN(asin);
                }
                catch (WebException ex)
                {
                    //Log
                    throw;
                }
            }
            else
            {
                return(musicReleaseDetailModel);
            }

            var amazonCDItem  = releaseDetail.Items.Where(i => i.Source.ToLower() == "amazoncd").FirstOrDefault();
            var amazonMP3Item = releaseDetail.Items.Where(i => i.Source.ToLower() == "amazonmp3").FirstOrDefault();
            var itunesItem    = releaseDetail.Items.Where(i => i.Source.ToLower() == "itunes").FirstOrDefault();

            if (amazonCDItem == null && amazonMP3Item == null && itunesItem == null)
            {
                return(musicReleaseDetailModel);
            }

            musicReleaseDetailModel = new MusicReleaseCollection
            {
                PicUrl      = releaseDetail.PicUrl,
                ReleaseDate = releaseDetail.ReleaseDate,
                Asin        = releaseDetail.Asin,
                AmazonCD    = amazonCDItem,
                AmazonMP3   = amazonMP3Item,
                ITunes      = itunesItem
            };

            if (amazonCDItem != null)
            {
                musicReleaseDetailModel.Artist = amazonCDItem.Artist;
                musicReleaseDetailModel.Title  = amazonCDItem.Title;
            }
            else if (amazonMP3Item != null)
            {
                amazonMP3Item.Artist = amazonCDItem.Artist;
                amazonMP3Item.Title  = amazonCDItem.Title;
            }
            else if (itunesItem != null)
            {
                itunesItem.Artist = amazonCDItem.Artist;
                itunesItem.Title  = amazonCDItem.Title;
            }

            return(musicReleaseDetailModel);
        }
        public ReleaseDetailItem GetReleaseDetailsFromASIN(string inAsin)
        {
            var releaseDetailItem           = new ReleaseDetailItem();
            IList <SimpleItem> releaseItems = new List <SimpleItem>();

            var amazonSearch       = new AmazonItemSearch(_amazonItemRepo);
            var amazonSearchResult = amazonSearch.GetByASIN(inAsin);

            if (amazonSearchResult != null)
            {
                releaseDetailItem.Asin        = inAsin;
                releaseDetailItem.PicUrl      = amazonSearchResult.PicUrl;
                releaseDetailItem.ReleaseDate = amazonSearchResult.ReleaseDate;
                releaseItems.Add(new SimpleItem
                {
                    Artist = amazonSearchResult.Artist,
                    Title  = amazonSearchResult.Title,
                    Url    = amazonSearchResult.Url,
                    Price  = amazonSearchResult.Price,
                    Source = "AmazonCD"
                });

                var searchTerm = amazonSearchResult.Artist + " " + amazonSearchResult.Title;
                var mp3Result  = amazonSearch.GetBySearchTerm(searchTerm, SearchIndex.MP3);

                if (mp3Result != null)
                {
                    releaseItems.Add(new SimpleItem
                    {
                        Artist = mp3Result.Artist,
                        Title  = mp3Result.Title,
                        Url    = mp3Result.Url,
                        Price  = mp3Result.Price,
                        Source = "AmazonMP3"
                    });
                }

                //Lookup iTunes
                var iTunesSearch = new ItunesItemSearch(_itunesItemRepo);
                var iTunesResult = iTunesSearch.GetBySearchTerm(searchTerm);

                if (iTunesResult != null)
                {
                    releaseItems.Add(new SimpleItem
                    {
                        Artist = iTunesResult.Artist,
                        Title  = iTunesResult.Title,
                        Url    = iTunesResult.Url,
                        Price  = iTunesResult.Price,
                        Source = "ITunes"
                    });
                }
            }
            releaseDetailItem.Items = releaseItems;

            return(releaseDetailItem);
        }