public HttpResponseMessage GetFreeDrivers([FromUri] string type) { List <Driver> drivers = null; drivers = DataRepository._driverRepo.RetriveAllDrivers().ToList(); if (drivers != null) { Enums.CarTypes car = (Enums.CarTypes)Enum.Parse(typeof(Enums.CarTypes), type); if (car != Enums.CarTypes.Bez_Naznake) { drivers.RemoveAll(d => (d.Occupied == true) || (d.Car.Type != car)); } else { drivers.RemoveAll(d => d.Occupied == true); } return(Request.CreateResponse(HttpStatusCode.OK, drivers)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } }
public HttpResponseMessage GetFreeDriversByLen([FromUri] string type, double x, double y) { List <Driver> drivers = null; drivers = DataRepository._driverRepo.RetriveAllDrivers().ToList(); if (drivers != null) { Enums.CarTypes car = (Enums.CarTypes)Enum.Parse(typeof(Enums.CarTypes), type); if (car != Enums.CarTypes.Bez_Naznake) { drivers.RemoveAll(d => (d.Occupied == true) || (d.Car.Type != car)); drivers.Sort(delegate(Driver d1, Driver d2) { if (CalculateLength(x, y, d1.Location.X, d1.Location.Y) < CalculateLength(x, y, d2.Location.X, d2.Location.Y)) { return(-1); } else { return(1); } }); if (drivers.Count > 5) { drivers.RemoveRange(5, drivers.Count - 5); } } else { drivers.RemoveAll(d => d.Occupied == true); drivers.Sort(delegate(Driver d1, Driver d2) { if (CalculateLength(x, y, d1.Location.X, d1.Location.Y) < CalculateLength(x, y, d2.Location.X, d2.Location.Y)) { return(-1); } else { return(1); } }); if (drivers.Count > 5) { drivers.RemoveRange(5, drivers.Count - 5); } } return(Request.CreateResponse(HttpStatusCode.OK, drivers)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } }