Пример #1
0
        public string Register(string user, string password, string defaultlocation)
        {
            int    userId;
            double lat, loong;

            if (!LocationHelper.IsPostcode(defaultlocation) && !(LocationHelper.IsLatLong(defaultlocation, out lat, out loong)))
            {
                return("");
            }

            // check if user already exists
            using (var db = new whatshotEntities1())
            {
                var userExists = (from User in db.Users
                                  where User.UserName == user
                                  select User).Any();

                if (userExists)
                {
                    return("");
                }

                var newUser = new User()
                {
                    UserName = user, HashedPassword = password, DefaultLocation = defaultlocation
                };

                db.Users.Add(newUser);
                db.SaveChanges();
                userId = newUser.Id;
            }

            return(_tokenHelper.CreateToken(userId));
        }
Пример #2
0
        public string GetUserProfile(string token)
        {
            // check if valid token & get user id
            int userId;

            if (!_tokenHelper.IsTokenValid(token, out userId))
            {
                return("Invalid token");
            }

            using (var db = new whatshotEntities1())
            {
                var query = from u in db.Users
                            where u.Id == userId
                            select u;

                var user = query.FirstOrDefault();

                if (user == null)
                {
                    return("No user");
                }

                return(user.DefaultLocation);
            }
        }
Пример #3
0
        public string PopulateRandomData()
        {
            using (var db = new whatshotEntities1())
            {
//                MakeSomePoints(51.62, -0.3, 0.15, db, 50);
                //MakeSomePoints(51.46, 0.106, 0.2, db, 50);
                //MakeSomePoints(51.46, 0.106, 0.4, db, 75);
                //MakeSomePoints(51.46, 0.106, 0.6, db, 100);

                //double latitude;
                //double longitude;
                //for (var i = 0; i < 50; i++)
                //{
                //    var angle = r.NextDouble() * Math.PI * 2;
                //    var distance = r.NextDouble() * 0.2;
                //    latitude = Math.Cos(angle)*distance + 51.46;
                //    longitude = Math.Sin(angle) * distance + 0.106;

                //    var newvote = new Location()
                //    {
                //        Lat = latitude.ToString(),
                //        Long = longitude.ToString(),
                //        TimeAdded = DateTime.Now,
                //        User_Id = -1//userId

                //    };
                //    db.Locations.Add(newvote);
                //}
                db.SaveChanges();
            }
            return("success");
        }
Пример #4
0
        public void SetUserProfile(string token, string defaultlocation)
        {
            // check if valid token & get user id
            int userId;

            if (!_tokenHelper.IsTokenValid(token, out userId))
            {
                return;
            }


            // check if default location is a valid location
            double lat, loong;

            if (!LocationHelper.IsPostcode(defaultlocation) && !LocationHelper.IsLatLong(defaultlocation, out lat, out loong))
            {
                return;
            }

            using (var db = new whatshotEntities1())
            {
                var query = from u in db.Users
                            where u.Id == userId
                            select u;

                var user = query.FirstOrDefault();

                user.DefaultLocation = defaultlocation;

                db.SaveChanges();
            }
        }
Пример #5
0
        public string PostDestination(string token, string lat, string @long)
        {
            // check if valid token & get user id
            //int userId;
            //if (!_tokenHelper.IsTokenValid(token, out userId)) return "Invalid token";

            double latitude, longitude;

            if (!LocationHelper.IsLat(lat, out latitude) || !(LocationHelper.IsLong(@long, out longitude)))
            {
                return("Invalid lat/long");
            }

            using (var db = new whatshotEntities1())
            {
                var newvote = new Location()
                {
                    Lat       = latitude.ToString(),
                    Long      = longitude.ToString(),
                    TimeAdded = DateTime.Now,
                    User_Id   = -1//userId
                };

                db.Locations.Add(newvote);
                db.SaveChanges();
            }

            return("blah");
        }
Пример #6
0
        /// <summary>
        /// delta 1 lat / long is roughly 110km = 110000m. We want roughly 10 meter increments
        /// </summary>
        /// <param name="token"></param>
        /// <param name="lat"></param>
        /// <param name="long"></param>
        /// <returns></returns>
        public HeatmapList GetHeatmapData(string token, string lat, string @long)
        {
            //int userId;
            //if (!_tokenHelper.IsTokenValid(token, out userId)) return dataForUser.ToArray();

            double latitude, longitude;

            if (!LocationHelper.IsLat(lat, out latitude) || !(LocationHelper.IsLong(@long, out longitude)))
            {
                return(null);
            }

            using (var db = new whatshotEntities1())
            {
                var locations = (from Locations in db.Locations
                                 select Locations).ToList();

                var list = new HeatmapList
                {
                    Locations = (from loc in locations.AsParallel()
                                 select new HeatmapData()
                    {
                        Latitude = loc.Lat, Longitude = loc.Long, Weight = 1
                    }).ToArray()
                };
                var num = list.Locations.Count();
                foreach (var l in list.Locations.Skip(num - 10))
                {
                    l.Weight = 10;
                }

                return(list);
            }
        }
Пример #7
0
        /// <summary>
        /// delta 1 lat / long is roughly 110km = 110000m. We want roughly 10 meter increments
        /// </summary>
        /// <param name="token"></param>
        /// <param name="lat"></param>
        /// <param name="long"></param>
        /// <returns></returns>
        public HeatmapList GetHeatmapData(string token, string lat, string @long)
        {
            //int userId;
            //if (!_tokenHelper.IsTokenValid(token, out userId)) return dataForUser.ToArray();

            double latitude, longitude;
            if (!LocationHelper.IsLat(lat, out latitude) || !(LocationHelper.IsLong(@long, out longitude))) return null;

            using (var db = new whatshotEntities1())
            {
                var locations = (from Locations in db.Locations
                                 select Locations).ToList();

                var list = new HeatmapList
                {
                    Locations =  (from loc in locations.AsParallel()
                           select new HeatmapData() { Latitude = loc.Lat, Longitude = loc.Long, Weight = 1 }).ToArray()
                };
                var num = list.Locations.Count();
                foreach (var l in list.Locations.Skip(num - 10))
                    l.Weight = 10;

                return list;
            }
        }
Пример #8
0
        public string GetData(string value)
        {
            using (var db = new whatshotEntities1())
            {
                var userCount = db.Users.Count();

                var newuser = new User() { Id = userCount + 1, UserName = "******", DefaultLocation = "", HashedPassword = "" };

                db.Users.Add(newuser);

                db.SaveChanges();

                return "success";
            }
        }
Пример #9
0
        public string Authenticate(string user, string password, string method)
        {
            int userId;
            using (var db = new whatshotEntities1())
            {
                var theuser = (from User in db.Users
                           where User.UserName == user && User.HashedPassword == password
                           select User).FirstOrDefault();

                if (theuser == null) return "";

                userId = theuser.Id;
            }

            return _tokenHelper.CreateToken(userId);
        }
Пример #10
0
        public string GetData(string value)
        {
            using (var db = new whatshotEntities1())
            {
                var userCount = db.Users.Count();

                var newuser = new User()
                {
                    Id = userCount + 1, UserName = "******", DefaultLocation = "", HashedPassword = ""
                };

                db.Users.Add(newuser);

                db.SaveChanges();

                return("success");
            }
        }
Пример #11
0
        public string Authenticate(string user, string password, string method)
        {
            int userId;

            using (var db = new whatshotEntities1())
            {
                var theuser = (from User in db.Users
                               where User.UserName == user && User.HashedPassword == password
                               select User).FirstOrDefault();

                if (theuser == null)
                {
                    return("");
                }

                userId = theuser.Id;
            }

            return(_tokenHelper.CreateToken(userId));
        }
Пример #12
0
        public string PopulateRandomData()
        {
            using (var db = new whatshotEntities1())
            {
            //                MakeSomePoints(51.62, -0.3, 0.15, db, 50);
                //MakeSomePoints(51.46, 0.106, 0.2, db, 50);
                //MakeSomePoints(51.46, 0.106, 0.4, db, 75);
                //MakeSomePoints(51.46, 0.106, 0.6, db, 100);

                //double latitude;
                //double longitude;
                //for (var i = 0; i < 50; i++)
                //{
                //    var angle = r.NextDouble() * Math.PI * 2;
                //    var distance = r.NextDouble() * 0.2;
                //    latitude = Math.Cos(angle)*distance + 51.46;
                //    longitude = Math.Sin(angle) * distance + 0.106;

                //    var newvote = new Location()
                //    {
                //        Lat = latitude.ToString(),
                //        Long = longitude.ToString(),
                //        TimeAdded = DateTime.Now,
                //        User_Id = -1//userId

                //    };
                //    db.Locations.Add(newvote);
                //}
                db.SaveChanges();
            }
            return "success";
        }
Пример #13
0
        private void MakeSomePoints(double latCentre, double lonCentre, double distanceRand, whatshotEntities1 db, int number)
        {
            var    r = new Random();
            double latitude;
            double longitude;

            for (var i = 0; i < number; i++)
            {
                var angle    = r.NextDouble() * Math.PI * 2;
                var distance = r.NextDouble() * distanceRand;
                latitude  = Math.Cos(angle) * distance + latCentre;
                longitude = Math.Sin(angle) * distance + lonCentre;

                var newvote = new Location()
                {
                    Lat       = latitude.ToString(),
                    Long      = longitude.ToString(),
                    TimeAdded = DateTime.Now,
                    User_Id   = -1,//userId
                };
                db.Locations.Add(newvote);
            }
        }
Пример #14
0
        public string PostDestination(string token, string lat, string @long)
        {
            // check if valid token & get user id
            //int userId;
            //if (!_tokenHelper.IsTokenValid(token, out userId)) return "Invalid token";

            double latitude, longitude;

            if (!LocationHelper.IsLat(lat, out latitude) || !(LocationHelper.IsLong(@long, out longitude))) return "Invalid lat/long";

            using (var db = new whatshotEntities1())
            {
                var newvote = new Location()
                {
                    Lat = latitude.ToString(),
                    Long = longitude.ToString(),
                    TimeAdded = DateTime.Now,
                    User_Id = -1//userId
                };

                db.Locations.Add(newvote);
                db.SaveChanges();
            }

            return "blah";
        }
Пример #15
0
        public string GetUserProfile(string token)
        {
            // check if valid token & get user id
            int userId;
            if (!_tokenHelper.IsTokenValid(token, out userId)) return "Invalid token";

            using (var db = new whatshotEntities1())
            {
                var query = from u in db.Users
                            where u.Id == userId
                            select u;

                var user = query.FirstOrDefault();

                if (user == null) return "No user";

                return user.DefaultLocation;
            }
        }
Пример #16
0
        private void MakeSomePoints(double latCentre, double lonCentre, double distanceRand, whatshotEntities1 db, int number)
        {
            var r = new Random();
            double latitude;
            double longitude;
            for (var i = 0; i < number; i++)
            {
                var angle = r.NextDouble() * Math.PI * 2;
                var distance = r.NextDouble() * distanceRand;
                latitude = Math.Cos(angle) * distance + latCentre;
                longitude = Math.Sin(angle) * distance + lonCentre;

                var newvote = new Location()
                {
                    Lat = latitude.ToString(),
                    Long = longitude.ToString(),
                    TimeAdded = DateTime.Now,
                    User_Id = -1,//userId

                };
                db.Locations.Add(newvote);
            }
        }
Пример #17
0
        public void SetUserProfile(string token, string defaultlocation)
        {
            // check if valid token & get user id
            int userId;
            if (!_tokenHelper.IsTokenValid(token, out userId)) return;

            // check if default location is a valid location
            double lat,loong;
            if (!LocationHelper.IsPostcode(defaultlocation) && !LocationHelper.IsLatLong(defaultlocation,out lat, out loong)) return;

            using (var db = new whatshotEntities1())
            {
                var query = from u in db.Users
                            where u.Id == userId
                            select u;

                var user = query.FirstOrDefault();

                user.DefaultLocation = defaultlocation;

                db.SaveChanges();
            }
        }
Пример #18
0
        public string Register(string user, string password, string defaultlocation)
        {
            int userId;
            double lat, loong;
            if (!LocationHelper.IsPostcode(defaultlocation) && !(LocationHelper.IsLatLong(defaultlocation,out lat, out loong))) return "";

            // check if user already exists
            using (var db = new whatshotEntities1())
            {
                var userExists = (from User in db.Users
                                  where User.UserName == user
                                  select User).Any();

                if (userExists) return "";

                var newUser = new User() { UserName = user, HashedPassword = password, DefaultLocation = defaultlocation };

                db.Users.Add(newUser);
                db.SaveChanges();
                userId = newUser.Id;
            }

            return _tokenHelper.CreateToken(userId);
        }