public HttpResponseMessage UpdateDeviceToken(UpdateToken token) { try { var userID = User.Identity.GetUserId(); var isAdmin = User.IsInRole("Admin"); var tbl_DeviceIds = db.tbl_DeviceIds.FirstOrDefault(d => d.col_UserID == userID); if (tbl_DeviceIds != null) { tbl_DeviceIds.col_UserID = userID; tbl_DeviceIds.col_DeviceToken = token.token; tbl_DeviceIds.col_Version = token.appVersion; tbl_DeviceIds.col_DateTime = DateTime.Now; if (isAdmin) { tbl_DeviceIds.col_UserType = "Admin"; } else { tbl_DeviceIds.col_UserType = "User"; } db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Updated")); } else { tbl_DeviceIds ids = new tbl_DeviceIds(); ids.col_UserID = userID; ids.col_DeviceToken = token.token; ids.col_Version = token.appVersion; if (isAdmin) { ids.col_UserType = "Admin"; } else { ids.col_UserType = "User"; } ids.col_DateTime = DateTime.Now; db.tbl_DeviceIds.Add(ids); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Added")); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.NotAcceptable, ex.Message)); } }
public IHttpActionResult RegistrationTry(RegisterBindingModel model) { AspNetUsersRegistring user = null; try { DAVEntities db = new DAVEntities(); user = new AspNetUsersRegistring(); user.FirstName = model.FirstName; user.LastName = model.LastName; user.DateOfBirth = model.DateOfBirth; user.Address = model.Address; user.City = model.City; user.State = model.State; user.PostalCode = model.PostalCode; user.PhoneNumber = model.PhoneNumber; user.RollNo = model.RollNo; user.Posting = model.Posting; user.JoiningYear = model.JoiningYear; user.LeavingYear = model.LeavingYear; user.BloodGroup = model.BloodGroup; user.House = model.House; user.Designation = model.Designation; user.Department = model.DepartMent; user.School = model.School; user.Password = model.Password; user.ConfirmPassword = model.ConfirmPassword; user.DateTime = DateTime.Now; user.UserName = model.UserName; user.Email = model.Email; user.ProfileLink = model.ProfileLink; db.AspNetUsersRegistrings.Add(user); db.SaveChanges(); return(Ok("Success")); } catch (Exception ex) { return(Ok("Error" + user)); } }
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)); } }