예제 #1
0
        // GET: api/Musicians/instruments/genres/locationLatitude/locationLongitude
        public async Task <IHttpActionResult> GetMusicians(string instruments, string genres, string latitude, string longitude)
        {
            var instrumentIds = instruments.Split(',').Select(int.Parse).ToList();
            var genreIds      = genres.Split(',').Select(int.Parse).ToList();

            var musicians = await db.Musicians.ToListAsync();

            var result = musicians.Where(musician => musician.Instruments.Any(x => instrumentIds.Any(y => y == x.Id))).ToList();

            result = result.Where(musician => musician.Genres.Any(x => genreIds.Any(y => y == x.Id))).ToList();

            return(Ok(result.OrderBy(
                          x =>
                          LocationHelper.GetDistanceKM(x.LocationLatitude, x.LocationLongitude, Convert.ToDouble(latitude),
                                                       Convert.ToDouble(longitude)))));
        }