Ejemplo n.º 1
0
        public bool IsDiscountAvailable(int userId, int albumId)
        {
            if (albumId <= 0 || userId <= 0)
            {
                throw new ArgumentException("userId is less then 1 or albumId is less then 1 in musicStoreService in BuySong", "userId or albumId");
            }

            User user = _userRepository.GetItem(userId);

            if (user == null)
            {
                throw new Exception("Can not find user in db");
            }

            Album album = _albumRepository.GetItem(albumId);

            if (album == null)
            {
                throw new Exception("Can not find album in db");
            }

            foreach (var albumSong in album.Songs)
            {
                if (user.BoughtSongs.Any(x => x.Song.Id == albumSong.Id))
                {
                    return(false);
                }
            }
            return(true);
        }
        public IList <Domain.DataTransfer.Song> GetSongsListFromAlbum(int albumId)
        {
            if (albumId <= 0)
            {
                throw new ArgumentException($"{nameof(albumId)} is less then 1 in musicStoreService DisplayAllAvailableSongs", nameof(albumId));
            }

            var album = _albumRepository.GetItem(albumId);

            if (album == null || album.Songs == null)
            {
                throw new Exception("album is null or album.Songs is null");
            }

            var domainSongsList = album.Songs.Select(_mapSong.AutoMap).ToList();

            return(domainSongsList);
        }