示例#1
0
        public ActionResult About()
        {
            //Only For Development
            var xip = Request.Headers["X-Forwarded-For"].Split(new char[] { ',' }).FirstOrDefault();

            using (var reader = new DatabaseReader(HostingEnvironment.MapPath("~/assets/GeoIP2/GeoLite2-City.mmdb")))
            {
                // Get the city from the IP Address
                var city = reader.City(xip);

                //Get Country AdInfo
                var builder = Builders <AdInfo> .Filter;
                var filter  = builder.Type("CampaignId", BsonType.Null) & builder.Eq("AdCountry", city.Country) &
                              builder.Eq("AdStatus", true);
                var passAd = _dbContext.AdInfos.Find(filter).ToList();

                List <PassAd> pAd = new List <PassAd>();
                foreach (var adInfo in passAd)
                {
                    var ad = new PassAd
                    {
                        AdType    = adInfo.AdType,
                        ImageUrl  = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString(),
                        VideoUrl  = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
                        VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
                    };

                    pAd.Add(ad);
                }

                var passitonViewModel = new PassItOnViewModel()
                {
                    PassItAds = pAd
                };

                return(View(passitonViewModel));
            }
        }
示例#2
0
        public ActionResult Index()
        {
            //Only For Development
            //Get Country AdInfo
            var builder = Builders <AdInfo> .Filter;
            var filter  = builder.Type("CampaignId", BsonType.Null) & builder.Eq("AdCountry", "Ghana") &
                          builder.Eq("AdStatus", true);
            var passAd = _dbContext.AdInfos.Find(filter).ToList();

            List <PassAd> pAd = new List <PassAd>();

            foreach (var adInfo in passAd)
            {
                if (adInfo.AdType.Equals("Background-Image"))
                {
                    var ad = new PassAd
                    {
                        AdType   = adInfo.AdType,
                        ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
                    };
                    pAd.Add(ad);
                }
                else if (adInfo.AdType.Equals("Background-Audio"))
                {
                    var ad = new PassAd
                    {
                        AdType   = adInfo.AdType,
                        ImageUrl = adInfo.AdMedia.GetElement("AudioUrl").Value.ToString()
                    };
                    pAd.Add(ad);
                }
                else if (adInfo.AdType.Equals("Background-Video(mute)"))
                {
                    var ad = new PassAd
                    {
                        AdType    = adInfo.AdType,
                        VideoUrl  = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
                        VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
                    };
                    pAd.Add(ad);
                }
                else if (adInfo.AdType.Equals("PassItCode-Image"))
                {
                    var ad = new PassAd
                    {
                        AdType   = adInfo.AdType,
                        ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
                    };
                    pAd.Add(ad);
                }
                else if (adInfo.AdType.Equals("PassItCode-Video"))
                {
                    var ad = new PassAd
                    {
                        AdType    = adInfo.AdType,
                        VideoUrl  = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
                        VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
                    };
                    pAd.Add(ad);
                }
                else if (adInfo.AdType.Equals("PhoneNo-Image(Default)"))
                {
                    var ad = new PassAd
                    {
                        AdType   = adInfo.AdType,
                        ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
                    };
                    pAd.Add(ad);
                }
                else if (adInfo.AdType.Equals("PhoneNo-Video(Default)"))
                {
                    var ad = new PassAd
                    {
                        AdType    = adInfo.AdType,
                        VideoUrl  = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
                        VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
                    };
                    pAd.Add(ad);
                }
            }

            var passitonViewModel = new PassItOnViewModel()
            {
                PassItAds = pAd
            };

            return(View(passitonViewModel));

            /*var xip = Request.Headers["X-Forwarded-For"].Split(new char[] { ',' }).FirstOrDefault();
             * using (var reader = new DatabaseReader(HostingEnvironment.MapPath("~/assets/GeoIP2/GeoLite2-City.mmdb")))
             * {
             *  // Get the city from the IP Address
             *  var city = reader.City(xip);
             * }*/

            //Uncomment Before Hosting

            /*using (var reader = new DatabaseReader(HostingEnvironment.MapPath("~/assets/GeoIP2/GeoLite2-City.mmdb")))
             * {
             *  // Determine the IP Address of the request
             *  var ipAddress = Request.UserHostAddress;
             *
             *  // Get the city from the IP Address
             *  var city = reader.City(ipAddress);
             *
             *  if (city != null)
             *  {
             *      //Get Country AdInfo
             *      var builder = Builders<AdInfo>.Filter;
             *      var filter = builder.Type("CampaignId", BsonType.Null) & builder.Eq("AdCountry", city.Country) &
             *                   builder.Eq("AdStatus", true);
             *      var passAd = _dbContext.AdInfos.Find(filter).ToList();
             *
             *      List<PassAd> pAd = new List<PassAd>();
             *      foreach (var adInfo in passAd)
             *      {
             *          if (adInfo.AdType.Equals("Background-Image"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("Background-Audio"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  ImageUrl = adInfo.AdMedia.GetElement("AudioUrl").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("Background-Video(mute)"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
             *                  VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("PassItCode-Image"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("PassItCode-Video"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
             *                  VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("PhoneNo-Image(Default)"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("PhoneNo-Video(Default)"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
             *                  VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *
             *      }
             *
             *      var passitonViewModel = new PassItOnViewModel()
             *      {
             *          PassItAds = pAd
             *      };
             *
             *      return View(passitonViewModel);
             *  }
             *  else
             *  {
             *      //Get Country AdInfo
             *      var builder = Builders<AdInfo>.Filter;
             *      var filter = builder.Type("CampaignId", BsonType.Null) & builder.Eq("AdCountry", "Ghana") &
             *                   builder.Eq("AdStatus", true);
             *      var passAd = _dbContext.AdInfos.Find(filter).ToList();
             *
             *      List<PassAd> pAd = new List<PassAd>();
             *      foreach (var adInfo in passAd)
             *      {
             *          if (adInfo.AdType.Equals("Background-Image"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("Background-Audio"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  ImageUrl = adInfo.AdMedia.GetElement("AudioUrl").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("Background-Video(mute)"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
             *                  VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("PassItCode-Image"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("PassItCode-Video"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
             *                  VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("PhoneNo-Image(Default)"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *          else if (adInfo.AdType.Equals("PhoneNo-Video(Default)"))
             *          {
             *              var ad = new PassAd
             *              {
             *                  AdType = adInfo.AdType,
             *                  VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
             *                  VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
             *              };
             *              pAd.Add(ad);
             *          }
             *
             *      }
             *
             *      var passitonViewModel = new PassItOnViewModel()
             *      {
             *          PassItAds = pAd
             *      };
             *
             *      return View(passitonViewModel);
             *  }
             * }*/
        }
示例#3
0
        public ActionResult Index()
        {
            //var xip = "41.139.29.42";
            var xip = "";

            xip = Request.UserHostAddress;
            if (Request.Headers["X-Forwarded-For"] != null)
            {
                xip = Request.Headers["X-Forwarded-For"];
            }
            else if (Request.Headers["REMOTE_ADDR"] != null)
            {
                xip = Request.Headers["REMOTE_ADDR"];
            }

            if (xip != null && xip.IndexOf(",", StringComparison.Ordinal) > 0)
            {
                string[] arIPs = xip.Split(',');

                xip = arIPs.First();
            }

            //Get User Country
            var userCountry = GetUserInfo(xip);

            //Get Country AdInfo
            var builder = Builders <AdInfo> .Filter;
            var filter  = builder.Type("CampaignId", BsonType.Null) & builder.Eq("AdType", "LookSharp-Video") & builder.Eq("AdCountry", userCountry.Result) & builder.Eq("AdStatus", true);
            var passAd  = _dbContext.AdInfos.Find(filter).ToList();


            //Get LookSharp Time   NOTE: GET USER'S TIME FOR TIME COMPARISON
            var builder2 = Builders <Campaign> .Filter;
            //var filter2 = builder2.Eq("CampaignCountry", userCountry.Result) & builder2.Eq("CampaignTitle", "LookSharp") & builder2.Gt("StartTime", DateTime.Now.ToUniversalTime()) & builder2.Eq("CampaignStatus", true);
            var filter2 = builder2.Eq("CampaignCountry", userCountry.Result) & builder2.Gt("StartTime", DateTime.Now.ToUniversalTime()) & builder2.Eq("CampaignStatus", true);

            var lookSharp = _dbContext.Campaigns.Find(filter2).FirstOrDefault();

            List <PassAd> pAd = new List <PassAd>();

            if (passAd.Count > 0 && lookSharp != null)
            {
                foreach (var adInfo in passAd)
                {
                    var ad = new PassAd
                    {
                        AdType    = adInfo.AdType,
                        VideoUrl  = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
                        VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString(),
                        StartTime = lookSharp.StartTime,
                        EndTime   = lookSharp.EndTime
                    };
                    pAd.Add(ad);

                    /*if (adInfo.AdType.Equals("Background-Image"))
                     * {
                     *  var ad = new PassAd
                     *  {
                     *      AdType = adInfo.AdType,
                     *      ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
                     *  };
                     *  pAd.Add(ad);
                     * }
                     * else if (adInfo.AdType.Equals("Background-Audio"))
                     * {
                     *  var ad = new PassAd
                     *  {
                     *      AdType = adInfo.AdType,
                     *      ImageUrl = adInfo.AdMedia.GetElement("AudioUrl").Value.ToString()
                     *  };
                     *  pAd.Add(ad);
                     * }
                     * else if (adInfo.AdType.Equals("Background-Video(mute)"))
                     * {
                     *  var ad = new PassAd
                     *  {
                     *      AdType = adInfo.AdType,
                     *      VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
                     *      VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
                     *  };
                     *  pAd.Add(ad);
                     * }
                     * else if (adInfo.AdType.Equals("PassItCode-Image"))
                     * {
                     *  var ad = new PassAd
                     *  {
                     *      AdType = adInfo.AdType,
                     *      ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
                     *  };
                     *  pAd.Add(ad);
                     * }
                     * else if (adInfo.AdType.Equals("PassItCode-Video"))
                     * {
                     *  var ad = new PassAd
                     *  {
                     *      AdType = adInfo.AdType,
                     *      VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
                     *      VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
                     *  };
                     *  pAd.Add(ad);
                     * }
                     * else if (adInfo.AdType.Equals("PhoneNo-Image(Default)"))
                     * {
                     *  var ad = new PassAd
                     *  {
                     *      AdType = adInfo.AdType,
                     *      ImageUrl = adInfo.AdMedia.GetElement("ImageUrl").Value.ToString()
                     *  };
                     *  pAd.Add(ad);
                     * }
                     * else if (adInfo.AdType.Equals("PhoneNo-Video(Default)"))
                     * {
                     *  var ad = new PassAd
                     *  {
                     *      AdType = adInfo.AdType,
                     *      VideoUrl = adInfo.AdMedia.GetElement("VideoUrl").Value.ToString(),
                     *      VideoHost = adInfo.AdMedia.GetElement("VideoHost").Value.ToString()
                     *  };
                     *  pAd.Add(ad);
                     * }*/
                }
            }
            else
            {
                var ad = new PassAd
                {
                    AdType   = "None",
                    ImageUrl = xip
                };
                pAd.Add(ad);
            }

            var passitonViewModel = new PassItOnViewModel()
            {
                PassItAds = pAd
            };

            return(View(passitonViewModel));
        }