Ejemplo n.º 1
0
        private void BtnOkMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (Current.Instance.Username == null || Current.Instance.Password == null || Current.Instance.Earthwatcher == null)
            {
                var ws = new WarningScreen(Labels.Flag1);
                ws.Show();

                _ignoreClick = true;
                Reset();
                return;
            }

            var comment = txtComment.Text;
            var eId     = Current.Instance.Earthwatcher.Id;

            //Get lat lon for flag
            var generalTransform         = imgFlagShadow.TransformToVisual(Current.Instance.MapControl);
            var childToParentCoordinates = generalTransform.Transform(new Point(15, imgFlagShadow.ActualHeight));
            var spherical = Current.Instance.MapControl.Viewport.ScreenToWorld(childToParentCoordinates.X, childToParentCoordinates.Y);
            var lonLat    = SphericalMercator.ToLonLat(spherical.X, spherical.Y);

            //Post
            var flagPost = new FlagRequests(Constants.BaseApiUrl);

            flagPost.FlagAdded += OnFlagAdded;
            var flag = new Earthwatchers.Models.Flag {
                Comment = comment, EarthwatcherId = eId, Latitude = lonLat.y, Longitude = lonLat.x
            };

            flagPost.Post(flag, Current.Instance.Username, Current.Instance.Password);

            _ignoreClick = true;
            Reset();
        }
Ejemplo n.º 2
0
 public HttpResponseMessage<Flag> PostFlag(Flag flag, HttpRequestMessage<Flag> request)
 {
     if (flag.EarthwatcherId != 0 && flag.Longitude != 0 & flag.Latitude != 0)
     {
         var newflag = flagRepository.PostFlag(flag);
         var response = new HttpResponseMessage<Flag>(newflag) { StatusCode = HttpStatusCode.Created };
         return response;
     }
     return null;
 }
Ejemplo n.º 3
0
 public void Post(Flag flag, string username, string password)
 {
     client.Authenticator = new HttpBasicAuthenticator(username, password);
     var request = new RestRequest("flags", Method.POST) { RequestFormat = DataFormat.Json };
     request.JsonSerializer = new JsonSerializer();
     request.AddBody(flag);
     client.ExecuteAsync<List<Flag>>(request, response =>
         Deployment.Current.Dispatcher.BeginInvoke(() =>
             FlagAdded(response.Data, null)
             ));
 }
        public Flag PostFlag(Flag flag)
        {
            connection.Open();
            //var cmd = connection.CreateCommand();
            //cmd.CommandText = "insert into Flags(EarthwatcherId, Location, Comment, Published) values(@userid, @location, @comment, @published) SET @ID = SCOPE_IDENTITY()";

            var cmd = connection.CreateCommand() as SqlCommand;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Flag_PostFlag";

            cmd.Parameters.Add(new SqlParameter("@userid", flag.EarthwatcherId));
            cmd.Parameters.Add(new SqlParameter("@location", SqlGeography.Point(flag.Latitude, flag.Longitude, 4326)) { UdtTypeName = "Geography" });
            cmd.Parameters.Add(new SqlParameter("@comment", flag.Comment));
            cmd.Parameters.Add(new SqlParameter("@published", DateTime.UtcNow.ToUniversalTime()));
            var idParameter = new SqlParameter("@ID", SqlDbType.Int) { Direction = ParameterDirection.Output };
            cmd.Parameters.Add(idParameter);
            cmd.ExecuteNonQuery();
            //var id = (int)idParameter.Value;
            //flag.Id = id;
            connection.Close();
            return flag;
        }
Ejemplo n.º 5
0
        private void BtnOkMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (Current.Instance.Username == null || Current.Instance.Password == null || Current.Instance.Earthwatcher == null)
            {
                var ws = new WarningScreen("Log in to place a flag");
                ws.Show();

                _ignoreClick = true;
                Reset();
                return;
            }
            
            var comment = txtComment.Text;
            var eId = Current.Instance.Earthwatcher.Id;

            //Get lat lon for flag
            var generalTransform = imgFlagShadow.TransformToVisual(Current.Instance.MapControl);
            var childToParentCoordinates = generalTransform.Transform(new Point(15, imgFlagShadow.ActualHeight));
            var spherical = Current.Instance.MapControl.Viewport.ScreenToWorld(childToParentCoordinates.X, childToParentCoordinates.Y);
            var lonLat = SphericalMercator.ToLonLat(spherical.X, spherical.Y);

            //Post
            var flagPost = new FlagRequests(Constants.BaseApiUrl);
            flagPost.FlagAdded += OnFlagAdded;  
            var flag = new Earthwatchers.Models.Flag { Comment = comment, EarthwatcherId = eId, Latitude = lonLat.y, Longitude = lonLat.x };
            flagPost.Post(flag, Current.Instance.Username, Current.Instance.Password);

            _ignoreClick = true;
            Reset();
        }