예제 #1
0
        public ResponseModel UpdateUserLocation(userLocationModel listModel)
        {
            var response = new ResponseModel
            {
                Success  = false,
                Messages = new List <string>()
            };

            if (listModel == null || string.IsNullOrEmpty(listModel.UserId) || string.IsNullOrEmpty(listModel.Cords))
            {
                response.Messages.Add("Data not mapped");
                response.Data = listModel;
            }
            else if (listModel.Cords.Split('_').Length != 2)
            {
                response.Messages.Add("Invalid Cord format. Please specify in Lat_Lang .i.e. '32.202895_74.176716'");
                response.Data = listModel;
            }
            else
            {
                try
                {
                    response.Success = UserService.UpdateUserLocation(listModel);
                    response.Data    = listModel;
                    response.Messages.Add(response.Success.ToString());
                }
                catch (Exception excep)
                {
                    response.Messages.Add("Something bad happened.");
                }
            }
            return(response);
        }
예제 #2
0
        public static bool UpdateUserLocation(userLocationModel requestModel)
        {
            DbGeography   userLoc = null;
            List <string> latlng  = new List <string>();

            if (!string.IsNullOrEmpty(requestModel.Cords) && requestModel.Cords != "")
            {
                latlng = requestModel.Cords.Split('_').ToList();
                if (latlng.Count == 2)
                {
                    userLoc = CommonService.ConvertLatLonToDbGeography(latlng[1], latlng[0]); // lat _ lng
                    using (var dbContext = new DeliversEntities())
                    {
                        var userlocmap = dbContext.Rider_Location_Map.FirstOrDefault(l => l.UserId == requestModel.UserId);
                        if (userlocmap == null)
                        {
                            var obj = new Rider_Location_Map
                            {
                                UserId      = requestModel.UserId,
                                Location    = userLoc,
                                LastUpdated = DateTime.Now
                            };
                            dbContext.Rider_Location_Map.Add(obj);
                        }
                        else
                        {
                            userlocmap.Location    = userLoc;
                            userlocmap.LastUpdated = DateTime.Now;
                        }
                        dbContext.SaveChanges();
                        return(true);
                    }
                }
            }
            return(false);
        }