public async Task <IEnumerable <Model.Airlines.Airline> > GetAirlines(AirlineSearchParameters param) { var airlines = repo.GetAirlines(); var temp = param; foreach (var a in airlines) { a.Flights = a.Flights.Where(i => { if (i.StartDate < temp.StartDate) { return(false); } if (i.StartDate > temp.EndDate) { return(false); } if (i.StartLocation.ToLower() != temp.StartLocation.ToLower()) { return(false); } if (i.EndLocation.ToLower() != temp.EndLocation.ToLower()) { return(false); } if (i.IsRoundTrip != temp.IsRoundTrip) { return(false); } if (temp.MultiCity && i.StopsLocations.Count == 0) { return(false); } if (i.FlightClass != (FlightClass)Enum.Parse(typeof(FlightClass), temp.FlightClass)) { return(false); } return(true); }).ToList(); } return(airlines.Where(i => i.Flights.Count() > 0)); }
public async Task <IActionResult> SearchAirlines(AirlineSearchParameters param) { if (!ModelState.IsValid) { return(BadRequest(new { Message = "Invalid search parameters supplied" })); } var ret = await service.GetAirlines(param); var temp = mapper.Map <IEnumerable <AirlineResource> >(ret); foreach (var a in temp) { var b = ret.First(i => i.Id == a.Id); if (b.Ratings.Count > 0) { a.Rating = b.Ratings.Sum(i => i.Rate) / b.Ratings.Count; } else { a.Rating = 0; } } return(Ok(new { Airlines = temp })); }