Пример #1
0
        public async Task <IHttpActionResult> Puttbl_Alerts(int id, tbl_Alerts tbl_Alerts)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tbl_Alerts.col_AlertID)
            {
                return(BadRequest());
            }

            db.Entry(tbl_Alerts).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tbl_AlertsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public IHttpActionResult Puttbl_UserLocation(UserLocation loc)
        {
            LogApi.Log(User.Identity.GetUserId(), "UpdateUserLocation from " + loc.Filter + " " + User.Identity.GetUserName());

            List <AspNetUser> list_AspNetUser = null;

            if (loc.Radius == 0)
            {
                loc.Radius = 50000;
            }
            else
            {
                loc.Radius = loc.Radius * 1000;
            }
            try
            {
                //Get employee
                var        userId     = User.Identity.GetUserId();
                AspNetUser AspNetUser = db.AspNetUsers.Where(e => e.Id == userId).FirstOrDefault();
                if (loc.Filter == "Batch")
                {
                    list_AspNetUser = db.AspNetUsers.Where(u => u.LeavingYear.Year == AspNetUser.LeavingYear.Year && u.School == AspNetUser.School).ToList();
                }
                else if (loc.Filter == "Branch")
                {
                    list_AspNetUser = db.AspNetUsers.ToList();
                }
                else if (loc.Filter == "School")
                {
                    list_AspNetUser = db.AspNetUsers.Where(u => u.School == AspNetUser.School).ToList();
                }
                else
                {
                    list_AspNetUser = db.AspNetUsers.ToList();
                }
                List <NearbyUsers> nearbyUserList = new List <NearbyUsers>();
                NearbyUsers        nearbyUsers;
                foreach (var x in list_AspNetUser.Where(u => u.Id != userId))
                {
                    GeoCoordinate eCoord = null;
                    if (loc.CitySearch)
                    {
                        eCoord = new GeoCoordinate(loc.CityLatitude, loc.CityLongitude);
                    }
                    else
                    {
                        eCoord = new GeoCoordinate((double)AspNetUser.Latitude, (double)AspNetUser.Longitude);
                    }
                    var    sCoord   = new GeoCoordinate(Convert.ToDouble(x.Latitude), Convert.ToDouble(x.Longitude));
                    double distance = sCoord.GetDistanceTo(eCoord);
                    if (distance < loc.Radius && distance > 0 && sCoord.Latitude != 0 && sCoord.Longitude != 0)
                    {
                        nearbyUsers             = new NearbyUsers();
                        nearbyUsers.Id          = x.Id;
                        nearbyUsers.FirstName   = x.FirstName;
                        nearbyUsers.LastName    = x.LastName;
                        nearbyUsers.Address     = x.Address;
                        nearbyUsers.BloodGroup  = x.BloodGroup;
                        nearbyUsers.City        = x.City;
                        nearbyUsers.Department  = x.Department;
                        nearbyUsers.School      = x.School;
                        nearbyUsers.Designation = x.Designation;
                        nearbyUsers.House       = x.House;
                        nearbyUsers.PostalCode  = x.PostalCode;
                        nearbyUsers.Posting     = x.Posting;
                        nearbyUsers.RollNo      = x.RollNo;
                        nearbyUsers.JoiningYear = x.JoiningYear;
                        nearbyUsers.LeavingYear = x.LeavingYear;
                        nearbyUsers.Distance    = distance;
                        nearbyUsers.PhoneNumber = x.PhoneNumber;
                        nearbyUsers.Profession  = x.Profession;
                        nearbyUsers.ProfileLink = x.ProfileLink;
                        if (x.LocationTime != null)
                        {
                            nearbyUsers.LocationDaysOld = Math.Abs(Math.Round((DateTime.Now - x.LocationTime).Value.TotalDays)).ToString() + " days ago";
                        }
                        else
                        {
                            nearbyUsers.LocationDaysOld = "No data available";
                        }
                        nearbyUserList.Add(nearbyUsers);
                    }
                }
                if (!loc.CitySearch)//Store city location data as user location data
                {
                    AspNetUser.Latitude        = (decimal)loc.Latitude;
                    AspNetUser.Longitude       = (decimal)loc.Longitude;
                    AspNetUser.LocationTime    = DateTime.Now;
                    db.Entry(AspNetUser).State = EntityState.Modified;
                    db.SaveChanges();
                }
                //nearbyUsers = nearbyUserList.Where(r => r.Distance == nearbyUserList.Min(d => d.Distance)).FirstOrDefault();
                if (nearbyUserList.Count > 0)
                {
                    //nearbyUsers = nearbyUserList.Where(r => r.Distance == nearbyUserList.Min(d => d.Distance)).FirstOrDefault();
                    return(Ok(nearbyUserList.OrderBy(u => u.Distance)));
                }
                else
                {
                    return(Ok("No records found"));
                }
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message));
            }
        }