Example #1
0
        //[OutputCache(VaryByParam = "*", Duration = 300)]
        public JsonResult hmGetAllRecentlyAddedData(string timestamp, string countryCode, string cityName)
        {
            List<hmUserData> list = new List<hmUserData>();
            DateTime timeStamp = DateTime.Now;
            if (timestamp == null)
                return this.Json(list, JsonRequestBehavior.AllowGet);
            try
            {
                timeStamp = DateTime.Parse(timestamp);
            }
            catch (Exception)
            {
                return this.Json(list, JsonRequestBehavior.AllowGet);
            }

            var cache = DataCache.Cache;
            if (isWhitelistedForHeatMap())
            {
                var context = new IPTV2Entities();
                if (!String.IsNullOrEmpty(countryCode) && !String.IsNullOrEmpty(cityName)) // getAllDataByCity
                {
                    string cacheKey = "HMGARAD:U:" + String.Format("{0}{1}{2}", countryCode, cityName, timeStamp) + ";C:" + MyUtility.getCountry(Request.GetUserHostAddressFromCloudflare()).getCode();
                    list = (List<hmUserData>)cache[cacheKey];
                    if (list == null)
                    {
                        var users = context.Users.Where(u => u.CountryCode.ToUpper() == countryCode.ToUpper() && u.City.ToUpper().Contains(cityName.ToUpper()) && u.RegistrationDate >= timeStamp && u.StatusId == GlobalConfig.Visible);
                        if (users != null)
                        {
                            list = new List<hmUserData>();
                            foreach (var user in users)
                            {
                                var item =
                                new hmUserData()
                                {
                                    FirstName = MyUtility.ToUpperFirstLetter(user.FirstName.ToLower()),
                                    CountryCode = user.CountryCode,
                                    City = MyUtility.ToUpperFirstLetter(user.City)
                                };
                                list.Add(item);
                            }
                            cache.Put(cacheKey, list, DataCache.CacheDuration);
                        }
                    }
                }
                else if (!String.IsNullOrEmpty(countryCode)) // getAllDataByCountry
                {
                    string cacheKey = "HMGARAD:U:" + String.Format("{0}{1}", countryCode, timeStamp) + ";C:" + MyUtility.getCountry(Request.GetUserHostAddressFromCloudflare()).getCode();
                    list = (List<hmUserData>)cache[cacheKey];
                    if (list == null)
                    {
                        var users = context.Users.Where(u => u.CountryCode.ToUpper() == countryCode.ToUpper() && u.RegistrationDate >= timeStamp && u.StatusId == GlobalConfig.Visible);
                        if (users != null)
                        {
                            list = new List<hmUserData>();
                            foreach (var user in users)
                            {
                                var item =
                                new hmUserData()
                                {
                                    FirstName = MyUtility.ToUpperFirstLetter(user.FirstName.ToLower()),
                                    CountryCode = user.CountryCode,
                                    City = MyUtility.ToUpperFirstLetter(user.City)
                                };
                                list.Add(item);
                            }
                            cache.Put(cacheKey, list, DataCache.CacheDuration);
                        }
                    }
                }
                else //getAllData
                {
                    string cacheKey = "HMGARAD:U:" + String.Format("{0}{1}", countryCode, timeStamp) + ";C:" + MyUtility.getCountry(Request.GetUserHostAddressFromCloudflare()).getCode();
                    list = (List<hmUserData>)cache[cacheKey];
                    if (list == null)
                    {
                        var users = context.Users.Where(u => u.RegistrationDate >= timeStamp && u.StatusId == GlobalConfig.Visible);
                        if (users != null)
                        {
                            list = new List<hmUserData>();
                            foreach (var user in users)
                            {
                                var item =
                                new hmUserData()
                                {
                                    FirstName = MyUtility.ToUpperFirstLetter(user.FirstName.ToLower()),
                                    CountryCode = user.CountryCode,
                                    City = MyUtility.ToUpperFirstLetter(user.City)
                                };
                                list.Add(item);
                            }
                            cache.Put(cacheKey, list, DataCache.CacheDuration);
                        }
                    }
                }
            }
            return this.Json(list, JsonRequestBehavior.AllowGet);
        }
Example #2
0
        //Heat Map
        //[OutputCache(VaryByParam = "*", Duration = 300)]
        public ActionResult hmGetAllData(string countryCode, string cityName)
        {
            List<hmUserData> list = null;
            var cache = DataCache.Cache;
            if (isWhitelistedForHeatMap())
            {
                var context = new IPTV2Entities();
                if (!String.IsNullOrEmpty(countryCode) && !String.IsNullOrEmpty(cityName)) // getAllDataByCity
                {
                    string cacheKey = "HMGAD:U:" + String.Format("{0}{1}", countryCode, cityName) + ";C:" + MyUtility.getCountry(Request.GetUserHostAddressFromCloudflare()).getCode();
                    list = (List<hmUserData>)cache[cacheKey];
                    if (list == null)
                    {
                        var users = context.Users.Where(u => u.CountryCode.ToUpper() == countryCode.ToUpper() && u.City.ToUpper().Contains(cityName.ToUpper()) && u.StatusId == GlobalConfig.Visible);
                        if (users != null)
                        {
                            list = new List<hmUserData>();
                            foreach (var user in users)
                            {
                                var item =
                                new hmUserData()
                                {
                                    FirstName = MyUtility.ToUpperFirstLetter(user.FirstName.ToLower()),
                                    CountryCode = user.CountryCode,
                                    City = MyUtility.ToUpperFirstLetter(user.City)
                                };
                                list.Add(item);

                            }
                            cache.Put(cacheKey, list, DataCache.CacheDuration);
                        }
                    }
                }
                else if (!String.IsNullOrEmpty(countryCode)) // getAllDataByCountry
                {
                    string cacheKey = "HMGAD:U:" + String.Format("{0}", countryCode) + ";C:" + MyUtility.getCountry(Request.GetUserHostAddressFromCloudflare()).getCode();
                    list = (List<hmUserData>)cache[cacheKey];
                    if (list == null)
                    {
                        var users = context.Users.Where(u => u.CountryCode.ToUpper() == countryCode.ToUpper() && u.StatusId == GlobalConfig.Visible);
                        if (users != null)
                        {
                            list = new List<hmUserData>();
                            foreach (var user in users)
                            {
                                var item =
                                new hmUserData()
                                {
                                    FirstName = MyUtility.ToUpperFirstLetter(user.FirstName.ToLower()),
                                    CountryCode = user.CountryCode,
                                    City = MyUtility.ToUpperFirstLetter(user.City)

                                };
                                list.Add(item);
                            }
                            cache.Put(cacheKey, list, DataCache.CacheDuration);
                        }
                    }
                }
                else //getAllData
                {
                    string cacheKey = "HMGAD:U:;C:" + MyUtility.getCountry(Request.GetUserHostAddressFromCloudflare()).getCode();
                    //list = (List<hmUserData>)cache[cacheKey];
                    if (list == null)
                    {
                        var users = context.Users.Where(u => u.StatusId == GlobalConfig.Visible).ToList();
                        if (users != null)
                        {
                            list = new List<hmUserData>();
                            foreach (var user in users)
                            {
                                var item =
                                new hmUserData()
                                {
                                    FirstName = MyUtility.ToUpperFirstLetter(user.FirstName.ToLower()),
                                    CountryCode = user.CountryCode,
                                    City = MyUtility.ToUpperFirstLetter(user.City)
                                };
                                list.Add(item);

                            }
                            // cache.Put(cacheKey, list, DataCache.CacheDuration);
                        }
                    }
                }
            }
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            serializer.MaxJsonLength = Int32.MaxValue;
            return Content(serializer.Serialize(list), "application/json");
            //return this.Json(list, JsonRequestBehavior.AllowGet);
        }