예제 #1
0
        public ActionResult AddPokemonLocation(int pokeIndexNum, double lng, double lat, DateTime date)
        {
            if (IsSpam(Request.UserHostAddress, Request.UserAgent))
            {
                return(Json("Nope", JsonRequestBehavior.AllowGet));
            }

            if (date > DateTime.UtcNow) // Bug.. Not going to be accurate between UTC and client Date. Maybe check if it's more than 1 day in the future? Fix it
            {
                date = DateTime.UtcNow;
            }

            var dateTime = new HourMinute()
            {
                DayOfWeek = date.DayOfWeek.ToString(),
                TimeOfDay = (date.Hour > 12) ? "PM" : "AM",
                Minute    = date.Minute,
                Hour      = ((date.Hour == 0 ? 12 : date.Hour) > 12 ? date.Hour - 12 : date.Hour),
                DateAdded = DateTime.UtcNow
            };

            var location = new PokemonLocation
            {
                Location     = new GeoJson2DGeographicCoordinates(lng, lat),
                LastSighted  = date,
                DateCreated  = DateTime.UtcNow,
                PokemonName  = LookupTable.GetPokemonName(pokeIndexNum),
                PokeIndexNum = pokeIndexNum,
                IpAddress    = Request.UserHostAddress,
                UserAgent    = Request.UserAgent,
                Times        = new List <HourMinute> {
                    dateTime
                }
            };

            var pokemon = _mongoService.AddLocation(location);

            return(Json(pokemon, JsonRequestBehavior.AllowGet));
        }