Exemplo n.º 1
0
        public SearchUserTravelPlanResponse SearchUserTravelPlans(SearchUserTravelPlanRequest requestModel)
        {
            SearchUserTravelPlanResponse response = new SearchUserTravelPlanResponse();

            var fromCity = _cityService.Search(x => x.RecordId == requestModel.FromCityId).FirstOrDefault();
            var toCity   = _cityService.Search(x => x.RecordId == requestModel.ToCityId).FirstOrDefault();

            if (fromCity == null)
            {
                throw new Exception("Başlangıç Şehri Bulunamamıştır.");
            }

            if (toCity == null)
            {
                throw new Exception("Varış Şehri Bulunamamıştır.");
            }

            var travels      = Search(x => x.TravelState == (int)ETravelState.Publish && x.FromCityId == requestModel.FromCityId && x.ToCityId == requestModel.ToCityId).ToList();
            var travelModels = _mapper.Map <List <UserTravelPlanModel> >(travels);

            Dictionary <string, CityCoordinateModel> coordinateMatris = new Dictionary <string, CityCoordinateModel>();

            coordinateMatris.Add("XMatris", new CityCoordinateModel {
                Value1 = fromCity.XLocation >= toCity.XLocation ? fromCity.XLocation : toCity.XLocation, Value2 = fromCity.XLocation < toCity.XLocation ? fromCity.XLocation : toCity.XLocation
            });
            coordinateMatris.Add("YMatris", new CityCoordinateModel {
                Value1 = fromCity.YLocation >= toCity.YLocation ? fromCity.YLocation : toCity.YLocation, Value2 = fromCity.YLocation < toCity.YLocation ? fromCity.YLocation : toCity.YLocation
            });

            var additionalTravels = Search(x => !travels.Select(s => s.RecordId).Contains(x.RecordId) && x.TravelState == (int)ETravelState.Publish &&
                                           ((x.FromCity.XLocation >= coordinateMatris["XMatris"].Value2 && x.FromCity.XLocation <= coordinateMatris["XMatris"].Value1) ||
                                            (x.FromCity.YLocation >= coordinateMatris["YMatris"].Value2 && x.FromCity.YLocation <= coordinateMatris["YMatris"].Value1))).ToList();

            response.UserTravelPlans       = travelModels;
            response.AdditionalTravelPlans = _mapper.Map <List <UserTravelPlanModel> >(additionalTravels);

            return(response);
        }
 public ActionResult <SearchUserTravelPlanResponse> SearchUserTravelPlans(SearchUserTravelPlanRequest Request)
 {
     return(_userTravelPlanService.SearchUserTravelPlans(Request));
 }