Exemple #1
0
        public AlbumDetail MapToDetailRep(DbAlbum a)
        {
            PublishedStatusEnumMapper statusMapper = new PublishedStatusEnumMapper();

            if (a == null)
            {
                throw new NullReferenceException($"A null value was passed to the mapper. Expected an object of type {nameof(DbAlbum)}");
            }
            List <AlbumTrack> tracks = a.Tracks
                                       .OrderByDescending(x => x.TrackNumber)
                                       .Select(x => new AlbumTrack()
            {
                Title             = x.Title,
                DurationInSeconds = x.DurationInSeconds,
                TrackNumber       = x.TrackNumber,
                TrackId           = x.Id
            }).OrderBy(x => x.TrackNumber).ToList();

            var album = new AlbumDetail
            {
                Id                     = a.Id,
                Title                  = a.Title,
                DescriptionText        = a.DescriptionText,
                CoverImageId           = a.AlbumCoverImageId,
                Price                  = a.Price,
                Producer               = a.Producer,
                Label                  = a.Label,
                ReleaseDate            = a.ReleaseDate,
                TotalDurationInSeconds = a.TotalDurationInSeconds,
                Tracks                 = tracks,
                  CoverImageUrl        = (a.AlbumCoverImageId.HasValue ? $"/api/image/{a.AlbumCoverImageId.Value}" : null),
                Genres                 = a.AlbumGenres.Select(g => g.Genre.Name).ToList(),
                CreatedUtc             = new DateTime(a.CreatedUtc.Ticks, DateTimeKind.Utc),
                UpdatedUtc             = new DateTime(a.UpdatedUtc.Ticks, DateTimeKind.Utc),
                PublishedStatus        = statusMapper.Map(a.PublishStatus),
                ArtistId               = a.ArtistId
            };

            if (a.Artist != null)
            {
                album.ArtistName = a.Artist.Name;
            }


            return(album);
        }
Exemple #2
0
        public ArtistDetail MapToDetailRep(DbArtist a)
        {
            PublishedStatusEnumMapper statusMapper = new PublishedStatusEnumMapper();

            if (a == null)
            {
                throw new NullReferenceException($"A null value was passed to the mapper. Expected an object of type {nameof(DbArtist)}");
            }
            return(new ArtistDetail
            {
                Id = a.Id,
                Name = a.Name,
                BioText = a.BioText,
                BioImageId = a.BioImageId,
                  BioImageUrl = (a.BioImageId.HasValue ? $"/api/image/{a.BioImageId.Value}" : null),
                Genres = a.ArtistGenres.Select(g => g.Genre.Name).ToList(),
                CreatedUtc = new DateTime(a.CreatedUtc.Ticks, DateTimeKind.Utc),
                UpdatedUtc = new DateTime(a.UpdatedUtc.Ticks, DateTimeKind.Utc),
                PublishedStatus = statusMapper.Map(a.PublishStatus)
            });
        }