public HttpResponseMessage SearchByRoutePath(string routePath) { MethodBase currentMethod = MethodBase.GetCurrentMethod(); AirlineLogManager.Entering(string.Format("key : {0}", routePath), currentClass, currentMethod); if (string.IsNullOrEmpty(routePath)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new SearchResponse { Messagecode = (int)HttpStatusCode.BadRequest, MessageDes = "routePath can not null or empty." })); } var path = routePath.Split('-').ToList(); IAirlineService airlineService = new AirlineService(); var result = airlineService.GetAllPaths(new SearchReq { source = path.FirstOrDefault(), destination = path.LastOrDefault() }); if (result.Any(x => x.Routepath == routePath)) { ShortestResponse ppp = result.Where(x => x.Routepath == routePath).FirstOrDefault(); return(Request.CreateResponse(HttpStatusCode.OK, ppp)); } else { return(Request.CreateResponse(HttpStatusCode.OK, new SearchResponse { Messagecode = (int)HttpStatusCode.OK, MessageDes = "Can not found this route path. Please try any route path again." })); } }
public HttpResponseMessage ShortestPath(SearchReq request) { MethodBase currentMethod = MethodBase.GetCurrentMethod(); if (request == null || string.IsNullOrEmpty(request.source) || string.IsNullOrEmpty(request.source)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new SearchResponse { Messagecode = (int)HttpStatusCode.BadRequest, MessageDes = "source or destination can not null or empty." })); } AirlineLogManager.Entering(string.Format("source: {0} to destination: {1}", request.source, request.destination), currentClass, currentMethod); Regex r = new Regex(@"^[A-I]{1}$"); if (!r.IsMatch(request.source) || !r.IsMatch(request.source)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new SearchResponse { Messagecode = (int)HttpStatusCode.BadRequest, MessageDes = "source or destination not match" })); } IAirlineService airlineService = new AirlineService(); ShortestResponse result = airlineService.GetShortestPath(request); return(Request.CreateResponse(HttpStatusCode.OK, result)); }