Exemplo n.º 1
0
        public static IPLocation GetIPLocation(string IPAddress)
        {
            IPLocation iplocation;

            string retJson = DownloadDataNoAuth(string.Format("http://www.freegeoip.net/json/{0}", IPAddress));

            var JO = JObject.Parse(retJson);

            iplocation = new IPLocation();

            iplocation.IPAddress = IPAddress;

            iplocation.CountryCode = JO["country_code"].ToString();

            iplocation.CountryName = JO["country_name"].ToString();

            return(iplocation);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            if (currency == null)
            {
                string client_ip = GetIPAddress();
                if (currency == null && !String.IsNullOrWhiteSpace(client_ip))
                {
                    iplocation = GetIPLocation(client_ip);
                    if (currency == null)
                    {
                        currency = "$ ";
                    }
                }
                else
                {
                    currency = "$ ";
                }
            }
            var euroCountries = new List <string>();

            euroCountries.AddRange(new String[] { "DE", "DK", "SE", "IT", "NL", "PL", "NO", "FI" });
            if (iplocation.CountryCode == "MY")
            {
                System.Web.HttpContext.Current.Items["currency"] = "RM ";
                currency = "RM ";
            }
            else if (euroCountries.Contains(iplocation.CountryCode))
            {
                System.Web.HttpContext.Current.Items["currency"] = "€ ";
                currency = "€ ";
            }
            else
            {
                System.Web.HttpContext.Current.Items["currency"] = "$ ";
                currency = "$ ";
            }
            return(View());
        }
        public ActionResult SearchResultPage(SearchFlightModel model)
        {
            if (currency == null)
            {
                string client_ip = GetIPAddress();
                if (currency == null)
                {
                    iplocation = HomeController.GetIPLocation(client_ip);
                    if (currency == null)
                    {
                        currency = "$ ";
                    }
                }
            }
            var euroCountries = new List <string>();

            euroCountries.AddRange(new String[] { "DE", "DK", "SE", "IT", "NL", "PL", "NO", "FI" });
            if (iplocation.CountryCode == "MY")
            {
                System.Web.HttpContext.Current.Items["currency"] = "RM ";
                currency = "RM ";
            }
            else if (euroCountries.Contains(iplocation.CountryCode))
            {
                System.Web.HttpContext.Current.Items["currency"] = "€ ";
                currency = "€ ";
            }
            else
            {
                System.Web.HttpContext.Current.Items["currency"] = "$ ";
                currency = "$ ";
            }
            using (var ctx = new UIA_Entities())
            {
                ApplicationUser appUser = UserManager.FindById(User.Identity.GetUserId());
                model.Name           = appUser.Name;
                model.Email          = appUser.Email;
                model.PhoneNumber    = appUser.PhoneNumber;
                model.UserId         = appUser.Id;
                model.PassportNumber = appUser.PassportNumber;

                model.DateOfBirth = appUser.DateOfBirth;
                model.Destination = (from table in ctx.Airports where table.Id == model.DestinationAirport select table.City).Single();
                model.Origin      = (from table in ctx.Airports where table.Id == model.OriginAirport select table.City).Single();
                model.Price       = (from table in ctx.Flights where table.fromAirport == model.OriginAirport where table.toAirport == model.DestinationAirport select table.Price).Single();
                TimeSpan timeTaken = (from table in ctx.Flights where table.fromAirport == model.OriginAirport where table.toAirport == model.DestinationAirport select table.DepartureTime).Single();
                model.Time = model.Date.Add(timeTaken);
                int duration = (from table in ctx.Flights where table.fromAirport == model.OriginAirport where table.toAirport == model.DestinationAirport select table.Duration).Single();
                model.ArrivalTime = model.Time.AddMinutes(duration);
                model.Duration    = duration.ToString() + " minutes";
                Console.WriteLine(model.Date);
                Console.WriteLine(model.Time);
                model.TotalPrice = model.Price;
                if (model.hasReturn)
                {
                    model.hasReturn                = true;
                    model.DestinationReturn        = model.Origin;
                    model.OriginReturn             = model.Destination;
                    model.DestinationAirportReturn = model.OriginAirport;
                    model.OriginAirportReturn      = model.DestinationAirport;
                    model.PriceReturn              = (from table in ctx.Flights where table.fromAirport == model.OriginAirportReturn where table.toAirport == model.DestinationAirportReturn select table.Price).Single();
                    TimeSpan timeTakenReturn = (from table in ctx.Flights where table.fromAirport == model.OriginAirportReturn where table.toAirport == model.DestinationAirportReturn select table.DepartureTime).Single();
                    model.TimeReturn = model.DateReturn.AddTicks(timeTakenReturn.Ticks);
                    int durationReturn = (from table in ctx.Flights where table.fromAirport == model.OriginAirportReturn where table.toAirport == model.DestinationAirportReturn select table.Duration).Single();
                    model.ArrivalTimeReturn = model.TimeReturn.AddMinutes(durationReturn);
                    model.DurationReturn    = durationReturn.ToString() + " minutes";
                    model.TotalPrice       += model.PriceReturn;
                }
            }
            return(View(model));
        }