Exemplo n.º 1
0
        public Musician AddMusician(AddMusicianRequestDto request)
        {
            var track = GetOrCreateTrack(request.Track);

            var musician = new Musician()
            {
                FirstName = request.FirstName,
                LastName  = request.LastName,
                NickName  = request.NickName
            };

            _context.Add(musician);

            if (track != null)
            {
                _context.Musician_Track.Add(new MusicianTrack()
                {
                    Musician = musician,
                    Track    = track
                });
            }

            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                return(null);
            }

            return(musician);
        }
Exemplo n.º 2
0
        public NewMusicianResponseDto AddNewMusician(NewMusicianRequestDto newMusicianRequestDto)
        {
            var musician = new Musician
            {
                FirstName = newMusicianRequestDto.FirstName,
                LastName  = newMusicianRequestDto.LastName,
                NickName  = newMusicianRequestDto.NickName,
            };

            var track = _context.Tracks.FirstOrDefault(t =>
                                                       t.TrackName.Equals(newMusicianRequestDto.Track.TrackName) &&
                                                       t.Duration.Equals(newMusicianRequestDto.Track.Duration)) ?? new Track
            {
                TrackName = newMusicianRequestDto.Track.TrackName,
                Duration  = newMusicianRequestDto.Track.Duration
            };

            var musicianTrack = new MusicianTrack
            {
                Musician = musician,
                Track    = track
            };

            _context.Add(musicianTrack);
            _context.SaveChanges();

            return(new NewMusicianResponseDto {
                IdMusician = musician.IdMusician,
                FirstName = musician.FirstName,
                LastName = musician.LastName,
                NickName = musician.NickName,
                Track = new NewTrackResponseDto
                {
                    IdTrack = track.IdTrack,
                    TrackName = track.TrackName,
                    Duration = track.Duration
                }
            });
        }