コード例 #1
0
 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." });
     }
 }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: Crispried/RestRate
 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,
                 RestarauntType = RestarauntList[i].RestarauntType,
                 Longitude = RestarauntList[i].Longitude,
                 Latitude = RestarauntList[i].Latitude,
                 RestaurantIDNameFullAddress = PartOfObject,
             };
             RestIDNameFullAddressRates.Add(FullObject);
         }
         return Json(new { result = RestIDNameFullAddressRates });
     }
     catch
     {
         return Json(new { result = "Oooops! Something wrong with DB connection." });
     }
 }