public static void PublishLocation(Friend friend, EventHandler<PublishLocationEventArgs> callback)
 {
     var serializer = new Hammock.Serialization.HammockDataContractJsonSerializer();
     RestClient client = new RestClient
     {
         Authority = baseUrl,
         Timeout = new TimeSpan(0, 0, 0, _timeOut),
         Serializer = serializer,
         Deserializer = serializer
     };
     RestRequest request = new RestRequest
     {
         Timeout = new TimeSpan(0, 0, 0, _timeOut),
         Method = WebMethod.Post,
         Path = "PublishLocation",
         Entity = friend
     };
     publishlocationcallback = callback;
     try
     {
         client.BeginRequest(request, new RestCallback<bool>(PublishLocationCallback));
     }
     catch (Exception ex)
     {
         publishlocationcallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = new WebException("Communication Error!", ex) });
     }
     
 }
        /// <summary>
        /// Publish user info
        /// </summary>
        /// <param name="friend">friend obj</param>
        /// <returns>true if success</returns>
        public static bool PublishLocation(Friend friend)
        {
            using (MyFriendsModelContainer ctx = new MyFriendsModelContainer())
            {
                Friend locateFriend = ctx.Friends.SingleOrDefault(f => f.Id == friend.Id);
                if (locateFriend == null)
                {
                    ctx.Friends.AddObject(friend);
                    ctx.ObjectStateManager.ChangeObjectState(friend, System.Data.EntityState.Added);
                }
                else
                { 
                    //update
                    locateFriend.FriendName = friend.FriendName;
                    locateFriend.FriendImageUrl = friend.FriendImageUrl;
                    locateFriend.LastUpdated = friend.LastUpdated;
                    locateFriend.LocationStr = string.Format("POINT({0} {1})", friend.Latitude, friend.Longitude);

                    ctx.ObjectStateManager.ChangeObjectState(locateFriend, System.Data.EntityState.Modified);
                }
                bool success = ctx.SaveChanges() > 0;
                if (success)
                {
                    //update geography field
                    ctx.ExecuteFunction("UpdateFriendLocationById", new ObjectParameter[]
                                {
                                    new ObjectParameter("FriendID", friend.Id), 
                                });
                }
                return success;
            }
        }
 public bool PublishLocation(Friend friend)
 {
     return FriendsRepository.PublishLocation(friend);
 }
 private void PublishLocationAction()
 {
     if (GpsLocation != Location.Unknown)
     {
         Friend myInfo = new Friend();
         myInfo.Id = Identification.GetDeviceId();
         myInfo.FriendName = MyName;
         myInfo.LastUpdated = DateTime.UtcNow;
         myInfo.LocationStr = string.Format("POINT({0} {1})", GpsLocation.Latitude, GpsLocation.Longitude);
         IsBusy = true;
         ServiceAgent.PublishLocation(myInfo, new EventHandler<PublishLocationEventArgs>(PublishLocationResult));
     }
     else
     {
         MessageBox.Show("GPS position not aquired yet!");
     }
 }