Ejemplo n.º 1
0
        /// <summary>
        /// Returns the album details using the specified currency and price level for album price.
        /// </summary>
        /// <param name="id">The album id.</param>
        /// <param name="currencyCode">
        /// The currency code for album price. If it doesn't specified than default currency is used.
        /// </param>
        /// <param name="priceLevelId">
        /// The price level for album price. If it doesn't specified than default price level is used.
        /// </param>
        /// <param name="userId">
        /// The current user id.
        /// </param>
        /// <returns>
        /// The information about album with the specified <paramref name="id"/> or <b>null</b> if album doesn't exist.
        /// </returns>
        public AlbumDetailsViewModel GetAlbumDetails(int id, int?currencyCode = null, int?priceLevelId = null, int?userId = null)
        {
            Album album;

            using (var repository = Factory.GetAlbumRepository())
            {
                album = repository.GetById(id, a => a.Artist);
            }

            var albumViewModel = ModelsMapper.GetAlbumDetailsViewModel(album);

            if (currencyCode == null)
            {
                currencyCode = ServiceHelper.GetDefaultCurrency(Factory).Code;
            }

            if (priceLevelId == null)
            {
                priceLevelId = ServiceHelper.GetDefaultPriceLevel(Factory);
            }

            using (var repository = Factory.GetAlbumTrackRelationRepository())
            {
                albumViewModel.TracksCount = repository.Count(r => r.AlbumId == albumViewModel.Id);
                if (albumViewModel.TracksCount > 0)
                {
                    using (var albumPriceRepository = Factory.GetAlbumPriceRepository())
                    {
                        using (var currencyRatesrepository = Factory.GetCurrencyRateRepository())
                        {
                            albumViewModel.Price =
                                PriceHelper.GetAlbumPrice(albumPriceRepository, currencyRatesrepository, id, currencyCode.Value, priceLevelId.Value);
                        }
                    }
                }
            }

            if (userId != null)
            {
                using (var repository = Factory.GetOrderAlbumRepository())
                {
                    albumViewModel.IsOrdered =
                        repository.Exist(o => o.UserId == userId && o.AlbumId == albumViewModel.Id);
                }

                using (var repository = Factory.GetPurchasedAlbumRepository())
                {
                    albumViewModel.IsPurchased =
                        repository.Exist(p => p.UserId == userId && p.AlbumId == albumViewModel.Id);
                }
            }

            return(albumViewModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the album price in the specified currency and price level.
        /// </summary>
        /// <param name="albumId">
        /// The album id.
        /// </param>
        /// <param name="currencyCode">
        /// The currency code for album price. If it doesn't specified than default currency is used.
        /// </param>
        /// <param name="priceLevelId">
        /// The price level for album price. If it doesn't specified than default price level is used.
        /// </param>
        /// <returns>
        /// The album price in the specified currency and price level or <b>null</b>.
        /// </returns>
        public PriceViewModel GetAlbumPrice(int albumId, int?currencyCode, int?priceLevelId)
        {
            if (currencyCode == null)
            {
                currencyCode = ServiceHelper.GetDefaultCurrency(Factory).Code;
            }

            if (priceLevelId == null)
            {
                priceLevelId = ServiceHelper.GetDefaultPriceLevel(Factory);
            }

            using (var repository = Factory.GetAlbumPriceRepository())
            {
                using (var currencyRatesrepository = Factory.GetCurrencyRateRepository())
                {
                    return(PriceHelper.GetAlbumPrice(repository, currencyRatesrepository, albumId, currencyCode.Value, priceLevelId.Value));
                }
            }
        }