Exemplo n.º 1
0
        public GetMusicianResponse getMusician(int id)
        {
            Musician            musician;
            IEnumerable <Track> tracks;

            try
            {
                musician = _context.Musicians.Where(m => m.IdMusician.Equals(id)).First();
            }catch (Exception e)
            {
                throw new Exception("Brak muzyka w bazie");
            }
            try
            {
                tracks = _context.Musician_Tracks.Join(_context.Tracks, mt => mt.IdTrack, t => t.IdTrack, (mt, t) => t);
            }
            catch (Exception e)
            {
                throw new Exception("Utworów w bazie");
            }
            var resp = new GetMusicianResponse();

            resp.FirstName = musician.FirstName;
            resp.LastName  = musician.LastName;
            resp.NickName  = musician.NickName;
            resp.Track     = tracks;
            return(resp);
        }
Exemplo n.º 2
0
        public GetMusicianResponse GetMusician(int id)
        {
            var musician = _context.Musicians
                           .Include(m => m.MusicianTracks)
                           .FirstOrDefault(m => m.IdMusician == id);

            if (musician == null)
            {
                throw new MusicianDoesNotExistsException("Musician does not exists!");
            }

            var tracks = _context.MusicianTracks
                         .Where(p => p.IdMusician == id)
                         .Include(p => p.Track)
                         .Select(p => p.Track)
                         .ToList();


            var response = new GetMusicianResponse
            {
                Musician = musician,
                Tracks   = tracks
            };

            return(response);
        }
Exemplo n.º 3
0
        public GetMusicianResponse GetMusician(int id)
        {
            GetMusicianResponse response = new GetMusicianResponse();

            var musician = _context.Musician.SingleOrDefault(m => m.IdMusician == id);

            if (musician == null)
            {
                throw new ArgumentException("Taki muzyk nie istnieje w bazie!");
            }

            response.FirstName = musician.FirstName;
            response.LastName  = musician.LastName;

            var musicianTracks = _context.MusicianTrack
                                 .Where(mt => mt.IdMusician == id)
                                 .Include(t => t.Track)
                                 .ToList();

            var tracks = new List <Track>();

            foreach (var mt in musicianTracks)
            {
                var x = _context.Track.Where(e => e.IdTrack == mt.IdTrack).FirstOrDefault();

                tracks.Add(x);
            }

            var tracksResp = new List <TrackResponse>();

            foreach (var e in tracks)
            {
                var tr = new TrackResponse();
                tr.TrackName = e.TrackName;
                tr.Duration  = e.Duration;

                tracksResp.Add(tr);
            }

            response.Tracks = tracksResp;

            return(response);
        }
Exemplo n.º 4
0
        public IActionResult GetMusicianInfo(int id)
        {
            Musician musician = _context.Musicians.Where(e => e.IdMusician == id).First();
            ICollection <MusicianTrack> MusicianTracks = musician.MusicianTracks;
            ICollection <Track>         tracks         = new ICollection <Track>();

            foreach (var i in MusicianTracks)
            {
                tracks.Add(i.Track);
            }
            GetMusicianResponse getMusicianResponse = new GetMusicianResponse();

            getMusicianResponse.IdMusician = musician.IdMusician;
            getMusicianResponse.FirstName  = musician.FirstName;
            getMusicianResponse.LastName   = musician.LastName;
            if (musician.NickName != null)
            {
                getMusicianResponse.NickName = musician.NickName;
            }
            getMusicianResponse.MusicianTracks = tracks;

            return(Ok(getMusicianResponse));
        }