public JsonResult GetRestaraunts() { try { int LanguageID = 1; List <RestarauntLang> RestarauntLangList = restLangRepository.GetAll(LanguageID); List <RestIDNameFullAddress> RestIDNameFullAddress = new List <RestIDNameFullAddress>(); RestIDNameFullAddress tmp; foreach (var rl in RestarauntLangList) { tmp = new RestIDNameFullAddress() { Address = rl.Address, RestarauntID = rl.RestarauntID, Locality = rl.Locality, Region = rl.Region, Country = rl.Country, Name = rl.Name }; RestIDNameFullAddress.Add(tmp); } return(Json(new { result = RestIDNameFullAddress })); } catch { return(Json(new { result = "Oooops! Something wrong with DB connection." })); } }
public ActionResult GetAllRestaurants() { int LanguageID = 1; try { List <RestarauntLang> RestarauntLangList = restLangRepository.GetAll(LanguageID); List <Restaraunt> RestarauntList = restRepository.GetAll(); List <RestIDNameFullAddressRates> RestIDNameFullAddressRates = new List <RestIDNameFullAddressRates>(); RestIDNameFullAddressRates FullObject; RestIDNameFullAddress PartOfObject; // повышаем производительность поскольку с учетом выбора конкретного языка // мн -во RestarauntList[i] будет прямо соответсвовать RestarauntLangList[i]. // Быть осторожным с удалением. Нельзя давать возможность удалить RestarauntLangList[i] // для какого то конкретного языка. Если удалять, то удалять только RestarauntList[i] и все RestarauntLangList[i] for (int i = 0; i < RestarauntList.Count; i++) { PartOfObject = new RestIDNameFullAddress() { Address = RestarauntLangList[i].Address, RestarauntID = RestarauntList[i].RestarauntID, Name = RestarauntLangList[i].Name, Country = RestarauntLangList[i].Country, Locality = RestarauntLangList[i].Locality, Region = RestarauntLangList[i].Region }; FullObject = new RestIDNameFullAddressRates() { InteriorRate = RestarauntList[i].InteriorRate, KitchenRate = RestarauntList[i].KitchenRate, MaintenanceRate = RestarauntList[i].MaintenanceRate, Longitude = RestarauntList[i].Longitude, Latitude = RestarauntList[i].Latitude, RestarauntType = RestarauntList[i].RestarauntType, RestaurantIDNameFullAddress = PartOfObject }; RestIDNameFullAddressRates.Add(FullObject); } var test = Json(RestIDNameFullAddressRates); var a = test.Data; return(Json(new { result = RestIDNameFullAddressRates })); } catch { return(Json(new { result = "Oooops! Something wrong with DB connection." })); } }
public ActionResult GetRestaurantsWithinRadius(GeoCoordinates geoCoordinates) { int LanguageID = 1; const double radius = 200; try { double Longtitude = Convert.ToDouble(geoCoordinates.Longitude); double Latitude = Convert.ToDouble(geoCoordinates.Latitude); List <Restaraunt> RestarauntList = restRepository.GetAllWithinRadius(Latitude, Longtitude, radius); int[] RestarauntIDArray = new int[RestarauntList.Count]; for (int i = 0; i < RestarauntIDArray.Length; i++) // подумать над оптимизацией { RestarauntIDArray[i] = RestarauntList[i].RestarauntID; } List <RestarauntLang> RestarauntLangList = restLangRepository.GetAllWithinRadius(RestarauntIDArray, LanguageID); List <RestIDNameFullAddressRates> RestIDNameFullAddressRates = new List <RestIDNameFullAddressRates>(); RestIDNameFullAddressRates FullObject; RestIDNameFullAddress PartOfObject; for (int i = 0; i < RestarauntList.Count; i++) { PartOfObject = new RestIDNameFullAddress() { Address = RestarauntLangList[i].Address, RestarauntID = RestarauntList[i].RestarauntID, Name = RestarauntLangList[i].Name, Country = RestarauntLangList[i].Country, Locality = RestarauntLangList[i].Locality, Region = RestarauntLangList[i].Region }; FullObject = new RestIDNameFullAddressRates() { InteriorRate = RestarauntList[i].InteriorRate, KitchenRate = RestarauntList[i].KitchenRate, MaintenanceRate = RestarauntList[i].MaintenanceRate, RestaurantIDNameFullAddress = PartOfObject }; } return(Json(new { result = RestIDNameFullAddressRates })); } catch { return(Json(new { result = "Oooops! Something wrong with DB connection." })); } }