Пример #1
0
        public void GetGeoLocation(string ip)
        {
            GeoLocationHelper.APIKey = AppSettings.GeoLocationAPIKey;
            string response = JsonConvert.SerializeObject(GeoLocationHelper.GetLocation(ip));

            WriteJSON(response);
        }
Пример #2
0
        public void GetLocationBanner()
        {
            var ip = GetIP();

            var location      = GeoLocationHelper.GetLocation(ip);
            var imagesBaseDir = URIHelper.BasePath + "/media/uploads/images/banners/homebanners/";

            var cityBaseDir = imagesBaseDir;

            if (location.City.Name != null)
            {
                cityBaseDir = imagesBaseDir + location.City.Name.ToLower() + "/";
            }
            else
            {
                cityBaseDir = imagesBaseDir + "others/";
            }

            var path = "";

            if (!Directory.Exists(cityBaseDir))
            {
                cityBaseDir = imagesBaseDir + "others/";
            }

            var currentMonth = DateTime.Now.Month;

            var subdir = "summer/";

            if (currentMonth > 10 || currentMonth < 3)
            {
                subdir = "winter/";
            }

            var filesInDir = Directory.GetFiles(cityBaseDir + subdir);

            var randomIndex = (new Random()).Next(0, filesInDir.Length);

            if (filesInDir.Length > 0)
            {
                var filePath = filesInDir[randomIndex];
                path = filePath.Replace(URIHelper.BasePath, "").Replace("\\", "/");
            }

            WriteJSON("{\"path\":\"" + path + "\"}");
        }
Пример #3
0
        public void GetLocation()
        {
            string response = JsonConvert.SerializeObject(GeoLocationHelper.GetLocation(GetIP()));

            WriteJSON(response);
        }