Example #1
0
        /// <summary>
        /// </summary>
        /// <param name="track">
        /// The track.
        /// </param>
        /// <param name="currencyCode">
        /// The currency code.
        /// </param>
        /// <param name="priceLevelId">
        /// The price level id.
        /// </param>
        /// <param name="userId">
        /// The user id.
        /// </param>
        /// <returns>
        /// </returns>
        private TrackDetailsViewModel CreateTrackDetailsViewModel(Track track, int?currencyCode = null, int?priceLevelId = null, int?userId = null)
        {
            if (track == null)
            {
                return(null);
            }

            var trackViewModel = ModelsMapper.GetTrackDetailsViewModel(track);

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

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

            using (var repository = Factory.GetTrackPriceRepository())
            {
                using (var currencyRatesrepository = Factory.GetCurrencyRateRepository())
                {
                    trackViewModel.Price =
                        PriceHelper.GetTrackPrice(repository, currencyRatesrepository, track.Id, currencyCode.Value, priceLevelId.Value);
                }
            }

            trackViewModel.Rating = ServiceHelper.CalculateTrackRating(Factory, track.Id);

            using (var repository = Factory.GetAlbumTrackRelationRepository())
            {
                trackViewModel.AlbumsCount = repository.Count(r => r.TrackId == track.Id);
            }

            if (userId != null)
            {
                using (var repository = Factory.GetOrderTrackRepository())
                {
                    trackViewModel.IsOrdered =
                        repository.Exist(o => o.UserId == userId && o.TrackId == trackViewModel.Id);
                }

                using (var repository = Factory.GetPurchasedTrackRepository())
                {
                    trackViewModel.IsPurchased =
                        repository.Exist(p => p.UserId == userId && p.TrackId == trackViewModel.Id);
                }
            }

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

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

            using (var repository = Factory.GetTrackPriceRepository())
            {
                using (var currencyRatesrepository = Factory.GetCurrencyRateRepository())
                {
                    return(PriceHelper.GetTrackPrice(repository, currencyRatesrepository, trackId, currencyCode.Value, priceLevelId.Value));
                }
            }
        }