private static void WriteReviews(RecordingDto recordingDto, RecordingDataSet.Recording recording) { recordingDto.reviews = new ReviewDto[recording.GetReviews().Length]; int index = 0; foreach (RecordingDataSet.Review review in recording.GetReviews()) { recordingDto.reviews[index++] = WriteReview(review); } }
private static void WriteTotalRuntime(RecordingDto dto, RecordingDataSet.Recording recording) { int runTime = 0; foreach (RecordingDataSet.Track track in recording.GetTracks()) { runTime += track.Duration; } dto.totalRunTime = runTime; }
WriteTracks(RecordingDto recordingDto, RecordingDataSet.Recording recording) { recordingDto.tracks = new TrackDto[recording.GetTracks().Length]; int index = 0; foreach (RecordingDataSet.Track track in recording.GetTracks()) { recordingDto.tracks[index++] = WriteTrack(track); } }
private static void WriteAverageRating(RecordingDto recordingDto, RecordingDataSet.Recording recording) { if (recording.GetReviews().Length == 0) { recordingDto.averageRating = 0; } else { int totalRating = 0; foreach (RecordingDataSet.Review review in recording.GetReviews()) { totalRating += review.Rating; } recordingDto.averageRating = totalRating / recording.GetReviews().Length; } }
WriteDto(RecordingDataSet.Recording recording) { RecordingDto dto = new RecordingDto(); dto.id = recording.Id; dto.title = recording.Title; dto.releaseDate = recording.ReleaseDate.ToShortDateString(); dto.artistName = recording.Artist.Name; dto.labelName = recording.Label.Name; WriteTracks(dto, recording); WriteTotalRuntime(dto, recording); WriteReviews(dto, recording); WriteAverageRating(dto, recording); return(dto); }