Esempio n. 1
0
        public bool Authenticate(string username, string passkey, string deviceid)
        {
            RedTrailEntities db = new RedTrailEntities();

            passkey = Utility.GetMd5Hash(passkey);
            return(db.RedUsers.Where(p => p.Username == username && p.PasswordHash == passkey).Any());
        }
Esempio n. 2
0
 public bool Register(UserForm user)
 {
     try
     {
         RedTrailEntities db = new RedTrailEntities();
         db.RedUsers.Add(new RedUser {
             Address1     = user.Address1,
             Address2     = user.Address2,
             Age          = user.Age,
             BloodGroup   = user.BloodGroup,
             ContactNo    = user.ContactNo,
             CreatedAt    = user.CreatedAt,
             Email        = user.Email,
             Gender       = user.Gender,
             IsDonor      = user.IsDonor,
             PasswordHash = Utility.GetMd5Hash(user.Password),
             Latitude     = user.Latitude,
             Longtitude   = user.Longtitude,
             Username     = user.Username,
             Location     = Utility.GetLocation(user.Latitude, user.Longtitude)
         });
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// This Script uses the Haversine Formula (shown below) expressed in terms of a two-argument inverse tangent function to calculate the great circle distance between two points on the Earth.
        /// This is the method recommended for calculating short distances by Bob Chamberlain ([email protected]) of Caltech and NASA's Jet Propulsion Laboratory as described on the U.S. Census Bureau Web site.
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longtitude"></param>
        /// <returns></returns>

        public static int GetLocation(string latitude, string longtitude)
        {
            RedTrailEntities db = new RedTrailEntities();

            RedLocation[] redlocations    = db.RedLocations.ToArray();
            double        dlat            = Convert.ToDouble(latitude);
            double        dlon            = Convert.ToDouble(longtitude);
            int           nearestId       = 0;
            double        nearestdistance = -1;

            foreach (var zone in redlocations)
            {
                double d = Calculate(dlat, dlon, Convert.ToDouble(zone.LatitudeMedian), Convert.ToDouble(zone.LongtitudeMedian));
                if (nearestdistance > 0 || d < nearestdistance)
                {
                    nearestId = zone.Id;
                }
            }
            return(nearestId);
        }
Esempio n. 4
0
        public UserForm[] SelectByZone(int Zoneid)
        {
            RedTrailEntities db = new RedTrailEntities();

            return(db.RedUsers.Where(p => p.RedLocation.Id == Zoneid).Select(p => new UserForm()
            {
                Address1 = p.Address1,
                Address2 = p.Address2,
                Age = p.Age,
                BloodGroup = p.BloodGroup,
                ContactNo = p.ContactNo,
                CreatedAt = p.CreatedAt,
                Email = p.Email,
                Gender = p.Gender,
                IsDonor = p.IsDonor,
                Zone = p.RedLocation.ZoneName,
                ZoneId = p.RedLocation.Id,
                Username = p.Username,
                Longtitude = p.Longtitude,
                Latitude = p.Latitude
            }).ToArray());
        }
Esempio n. 5
0
        public UserForm SelectOne(string username)
        {
            RedTrailEntities db = new RedTrailEntities();

            return(db.RedUsers.Where(p => p.Username == username).Select(p => new UserForm()
            {
                Address1 = p.Address1,
                Address2 = p.Address2,
                Age = p.Age,
                BloodGroup = p.BloodGroup,
                ContactNo = p.ContactNo,
                CreatedAt = p.CreatedAt,
                Email = p.Email,
                Gender = p.Gender,
                IsDonor = p.IsDonor,
                Zone = p.RedLocation.ZoneName,
                ZoneId = p.RedLocation.Id,
                Username = p.Username,
                Longtitude = p.Longtitude,
                Latitude = p.Latitude
            }).SingleOrDefault());
        }
Esempio n. 6
0
        public UserForm GetOne()
        {
            RedTrailEntities db   = new RedTrailEntities();
            RedUser          user = db.RedUsers.FirstOrDefault();

            return(new UserForm()
            {
                Address1 = user.Address1,
                Username = user.Username,
                Password = user.PasswordHash,
                Address2 = user.Address2,
                Age = user.Age,
                BloodGroup = user.BloodGroup,
                ContactNo = user.ContactNo,
                CreatedAt = user.CreatedAt,
                Email = user.Email,
                Gender = user.Gender,
                IsDonor = user.IsDonor,
                Latitude = user.Latitude,
                Longtitude = user.Longtitude
            });
        }
Esempio n. 7
0
        public UserForm[] Select()
        {
            //int pageSize = Convert.ToInt16(ConfigurationManager.AppSettings["paging"]);
            RedTrailEntities db = new RedTrailEntities();

            return(db.RedUsers.Select(p => new UserForm()
            {
                Address1 = p.Address1,
                Address2 = p.Address2,
                Age = p.Age,
                BloodGroup = p.BloodGroup,
                ContactNo = p.ContactNo,
                CreatedAt = p.CreatedAt,
                Email = p.Email,
                Gender = p.Gender,
                IsDonor = p.IsDonor,
                Zone = p.RedLocation.ZoneName,
                ZoneId = p.RedLocation.Id,
                Username = p.Username,
                Longtitude = p.Longtitude,
                Latitude = p.Latitude,
                Id = p.Id
            }).ToArray());
        }