public void UpdateEarthwatcher(int id, Earthwatcher earthwatcher)
 {
     try
     {
         connection.Open();
         var cmd = connection.CreateCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "Earthwatcher_UpdateEarthwatcher";
         cmd.Parameters.Add(new SqlParameter("@role", earthwatcher.Role));
         cmd.Parameters.Add(new SqlParameter("@country", earthwatcher.Country));
         cmd.Parameters.Add(new SqlParameter("@name", earthwatcher.Name));  //PARA CAMBIAR EL MAIL
         if (!string.IsNullOrEmpty(earthwatcher.Region))
         {
             cmd.Parameters.Add(new SqlParameter("@region", earthwatcher.Region));
         }
         else
         {
             cmd.Parameters.Add(new SqlParameter("@region", DBNull.Value));
         }
         cmd.Parameters.Add(new SqlParameter("@language", earthwatcher.Language));
         cmd.Parameters.Add(new SqlParameter("@notifyMe", earthwatcher.NotifyMe));
         cmd.Parameters.Add(new SqlParameter("@nickname", earthwatcher.NickName));
         cmd.Parameters.Add(new SqlParameter("@id", earthwatcher.Id));
         cmd.ExecuteNonQuery();
         connection.Close();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Esempio n. 2
0
        public HttpResponseMessage <Earthwatcher> GetLogged(HttpRequestMessage request)
        {
            Earthwatcher logged = null;

            try
            {
                if (Session.HasLoggedUser())
                {
                    logged = earthwatcherRepository.GetEarthwatcher(Session.GetCookieInfo().EarthwatcherName, true);
                    if (logged.Lands.Count == 0) //Si te estas logueando sin land y no hay land que agregarte, te asigno la del tutor
                    {
                        logged.Lands.Add(landRepository.GetTutorLand(logged.PlayingRegion));
                    }
                    return(new HttpResponseMessage <Earthwatcher>(logged)
                    {
                        StatusCode = HttpStatusCode.OK
                    });
                }
                return(new HttpResponseMessage <Earthwatcher>(logged)
                {
                    StatusCode = HttpStatusCode.OK
                });
            }
            catch
            {
                return(new HttpResponseMessage <Earthwatcher>(null)
                {
                    StatusCode = HttpStatusCode.InternalServerError
                });
            }
        }
Esempio n. 3
0
        void earthwatcherRequest_ApiEwReceived(object sender, EventArgs e)
        {
            Earthwatcher earthwatcher = sender as Earthwatcher;

            if (earthwatcher != null)
            {
                if (earthwatcher.Language == null) // || earthwatcher.Language.Equals("Spanish", StringComparison.InvariantCultureIgnoreCase))
                {
                    System.Threading.Thread.CurrentThread.CurrentCulture   = new CultureInfo("en");
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
                }
                else
                {
                    try
                    {
                        System.Threading.Thread.CurrentThread.CurrentCulture   = new CultureInfo(earthwatcher.Language);
                        System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(earthwatcher.Language);
                    }
                    catch
                    {
                        System.Threading.Thread.CurrentThread.CurrentCulture   = new CultureInfo("en");
                        System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
                    }
                }

                //earthwatcher.Password = password;
                SwitchControl(new MainPage(earthwatcher, geohexcode));
            }
            else
            {
                Earthwatchers.UI.App.BackToLoginPage();
            }
        }
Esempio n. 4
0
        public void LoadReportWindowContent(string geoHexCode)
        {
            //Limpio los bordes y rellenos de las manitos
            var noBorder = new Thickness(0);
            var white    = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));

            this.AlertButton.BorderThickness     = noBorder;
            this.AlertButton.Background          = white;
            this.OkButton.BorderThickness        = noBorder;
            this.OkButton.Background             = white;
            this.ConfirmButton.BorderThickness   = noBorder;
            this.ConfirmButton.Background        = white;
            this.DeconfirmButton.BorderThickness = noBorder;
            this.DeconfirmButton.Background      = white;

            //Muestro la ventanita
            this.Visibility = Visibility.Visible;

            //Oculto el TITLE y los grid de REPORTE, VERIFICACION, SHARE, DEMANDA. Mostrar FOOTER, COMMENTS, USER TITLE
            this.ValidateMessageText.Visibility = System.Windows.Visibility.Collapsed;
            this.Title.Visibility          = System.Windows.Visibility.Collapsed;
            this.ReportGrid.Visibility     = System.Windows.Visibility.Collapsed;
            this.ConfirmGrid.Visibility    = System.Windows.Visibility.Collapsed;
            this.DemandGrid.Visibility     = System.Windows.Visibility.Collapsed;
            this.ShareGrid.Visibility      = System.Windows.Visibility.Collapsed;
            this.FooterGrid.Visibility     = System.Windows.Visibility.Visible;
            this.commentsBorder.Visibility = System.Windows.Visibility.Visible;
            this.FincasGrid.Visibility     = System.Windows.Visibility.Visible;
            this.UserTitle.Visibility      = System.Windows.Visibility.Visible;
            //Luego de mostrar el shareGrid la animacion pone opacity 0 a las grillas de report y confirm
            this.ShareGrid.Opacity   = 0;
            this.ConfirmGrid.Opacity = 1;
            this.ReportGrid.Opacity  = 1;

            //Cargo los datos de la land y el earthwatcher de esa land
            foreach (var land in Current.Instance.LandInView)
            {
                if (land.GeohexKey.Equals(geoHexCode))
                {
                    selectedLand         = land;
                    selectedEarthwatcher = new Earthwatcher {
                        Name = selectedLand.EarthwatcherName, Id = selectedLand.EarthwatcherId.Value, IsPowerUser = selectedLand.IsPowerUser.Value
                    };
                }
            }

            if (selectedLand == null)
            {
                return;
            }

            if (selectedLand.DemandAuthorities == false) //Si es reporte o verificacion
            {
                LoadReportORVerificationGrid();
            }
            else //Si es Denuncia
            {
                LoadDenounceGrid();
            }
        }
Esempio n. 5
0
        private void ChangePlayingCountry(object sender, EventArgs e)
        {
            if (_selectedCountry != null)
            {
                Earthwatcher earthwatcher = Current.Instance.Earthwatcher;

                if (_selectedRegion != null && _selectedRegion.Id != 0)
                {
                    //TODO: GI REVISAR QUE PUEDA HACER UN CAMBIO DE PARCELA/PAIS EN X TIEMPO, sino se cambiarian siempre
                    if (earthwatcher.PlayingRegion != _selectedRegion.Id)
                    {
                        this.Visibility = System.Windows.Visibility.Collapsed;
                        ChangeStarted(this, EventArgs.Empty);
                        earthwatcher.PlayingCountry = _selectedRegion.CountryCode;
                        earthwatcher.PlayingRegion  = _selectedRegion.Id;
                        earthwatcherRequests.ChangePlayingRegion(earthwatcher);
                        this.errorMsj.Text       = "";
                        this.errorMsj.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        //Avisarle que ya esta jugando en ese pais/region!
                        this.errorMsj.Text       = Labels.ChangeCountryError;
                        this.errorMsj.Visibility = Visibility.Visible;
                    }
                }
                else
                {
                    //Avisarle que tiene que seleccionar una REGION de ese pais
                    this.errorMsj.Text       = Labels.ChangeCountryError2;
                    this.errorMsj.Visibility = Visibility.Visible;
                }
            }
        }
Esempio n. 6
0
        public ReportWindow(Land land, Earthwatcher earthwatcher)
        {
            InitializeComponent();

            commentRequests    = new CommentRequests(Constants.BaseApiUrl);
            collectionRequests = new CollectionRequests(Constants.BaseApiUrl);
            landRequests       = new LandRequests(Constants.BaseApiUrl);
            hexagonLayer       = (HexagonLayer)Current.Instance.LayerHelper.FindLayer(Constants.Hexagonlayername);
            bcLayer            = (BasecampLayer)Current.Instance.LayerHelper.FindLayer(Constants.BasecampsLayer); //TEST
            //Add event listeners
            commentRequests.CommentsByLandReceived += CommentRequestCommentsByLandReceived;
            collectionRequests.NewItemReceived     += collectionRequests_NewItemReceived;
            collectionRequests.ItemsCountReceived  += collectionRequests_ItemsCountReceived;
            collectionRequests.GetTotalItems(Current.Instance.Earthwatcher.Id);
            Current.Instance.MapControl.zoomFinished += MapControlZoomFinished;
            Current.Instance.MapControl.zoomStarted  += MapControlZoomStarted;


            landRequests = new LandRequests(Constants.BaseApiUrl);
            landRequests.StatusChanged     += SetLandStatusStatusChanged;
            landRequests.ConfirmationAdded += landRequests_ConfirmationAdded;

            hexagonLayer = (HexagonLayer)Current.Instance.LayerHelper.FindLayer(Constants.Hexagonlayername);

            this.Loaded += ReportWindow_Loaded;

            this.ShareStoryBoard.Completed += ShareStoryBoard_Completed;
        }
Esempio n. 7
0
        public HttpResponseMessage ForgotPassword(Earthwatcher earthwatcher, HttpRequestMessage <Earthwatcher> request)
        {
            if (earthwatcher != null)
            {
                var earthwatcherDb = earthwatcherRepository.GetEarthwatcher(earthwatcher.Name, false);
                if (earthwatcherDb == null)
                {
                    var response = new HttpResponseMessage(HttpStatusCode.NotFound);
                    return(response);
                }

                //Mando el mail
                try
                {
                    var    dateToEncode = System.Text.Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString());
                    string encodedDate  = System.Convert.ToBase64String(dateToEncode);

                    if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["smtp.enabled"]))
                    {
                        List <System.Net.Mail.MailMessage> messages = new List <System.Net.Mail.MailMessage>();

                        System.Net.Mail.MailAddress address     = new System.Net.Mail.MailAddress(earthwatcherDb.Name);
                        System.Net.Mail.MailAddress addressFrom = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["smtp.user"], "Guardianes - Greenpeace");
                        System.Net.Mail.MailMessage message     = new System.Net.Mail.MailMessage();
                        message.From = addressFrom;
                        message.To.Add(address);
                        message.Subject = "Reseteá tu contraseña de Guardianes - Reset your Guardians Password";

                        string domain = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority);

                        string htmlTemplate = System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mail.html"));
                        message.Body = string.Format(htmlTemplate, "Estimado Guardian,", "Para resetear tu contraseña hacé un click en el botón verde [Resetear Contraseña].<br><br> Por motivos de seguridad, este cambio se podrá hacer en el transcurso de las próximas 24 horas"
                                                     , string.Format("{0}/resetpwd.html?guid={1}&ed={2}", domain, earthwatcherDb.Guid, encodedDate), "Click aquí para resetear tu contraseña", "Resetear Contraseña", "Este mensaje se envío a", earthwatcherDb.Name
                                                     , ". Si no quieres recibir más notificaciones en un futuro podés acceder al Panel de Control del usuario y deshabilitar la opción de recibir notificaciones."
                                                     , "Greenpeace Argentina. Todos los derechos reservados.", domain);
                        message.IsBodyHtml   = true;
                        message.BodyEncoding = System.Text.Encoding.UTF8;
                        message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.None;
                        messages.Add(message);

                        SendMails.Send(messages);
                    }
                    return(new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK
                    });
                }
                catch (Exception ex)
                {
                    return(new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = ex.Message
                    });
                }
            }
            return(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.BadRequest
            });
        }
Esempio n. 8
0
        void earthwatcherRequest_EarthwatcherReceived(object sender, EventArgs e)
        {
            Earthwatcher earthwatcher = sender as Earthwatcher;

            if (earthwatcher != null)
            {
                if (earthwatcher.Language == null) // || earthwatcher.Language.Equals("Spanish", StringComparison.InvariantCultureIgnoreCase))
                {
                    System.Threading.Thread.CurrentThread.CurrentCulture   = new CultureInfo("en");
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
                }
                else
                {
                    try
                    {
                        System.Threading.Thread.CurrentThread.CurrentCulture   = new CultureInfo(earthwatcher.Language);
                        System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(earthwatcher.Language);
                    }
                    catch
                    {
                        System.Threading.Thread.CurrentThread.CurrentCulture   = new CultureInfo("en");
                        System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
                    }
                }

                earthwatcher.Password = password;
                SwitchControl(new MainPage(earthwatcher, geohexcode));
            }
            else
            {
                Earthwatchers.UI.App.BackToLoginPage();
                //string host = Application.Current.Host.Source.AbsoluteUri.Substring(0, Application.Current.Host.Source.AbsoluteUri.Length - 39);
                //System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("/index.html?action=logout", UriKind.Absolute), "_self");
            }
        }
Esempio n. 9
0
 public static void AddLinks(Earthwatcher earthwatcher, HttpRequestMessage request)
 {
     /*
      * var uriBuilder = new UriBuilder(request.RequestUri) {Path = earthwatcher.LandUri};
      * earthwatcher.LandUri=uriBuilder.Uri.ToString();
      *
      * uriBuilder.Path = earthwatcher.Uri;
      * earthwatcher.Uri = uriBuilder.Uri.ToString();
      * */
 }
Esempio n. 10
0
        public HttpResponseMessage <Earthwatcher> Post(Earthwatcher earthwatcher)
        {
            Earthwatcher earthwatcherResult = earthwatcherRepository.Post(earthwatcher);
            var          response           = new HttpResponseMessage <Earthwatcher>(earthwatcherResult);

            response.StatusCode = HttpStatusCode.Created;
            // todo set location in response
            //response.Headers.Location=new UriPathExtensionMapping(string.Format()
            return(response);
        }
Esempio n. 11
0
        /// <summary>
        /// Inserta en la tabla earthwatcher al usuario creado
        /// </summary>
        /// <param name="earthwatcher"></param>
        /// <returns></returns>
        public Earthwatcher CreateEarthwatcher(Earthwatcher earthwatcher)
        {
            var passwordPrefix = "";
            var hashedPassword = "";

            if (earthwatcher.Password != null)
            {
                passwordPrefix = PasswordChecker.GeneratePrefix();
                hashedPassword = PasswordChecker.GenerateHashedPassword(earthwatcher.Password, passwordPrefix);
            }
            connection.Open();
            var cmd = connection.CreateCommand() as SqlCommand;

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Earthwatcher_CreateEarthwatcher";
            cmd.Parameters.Add(new SqlParameter("@guid", earthwatcher.Guid));
            if (string.IsNullOrEmpty(earthwatcher.Name))
            {
                cmd.Parameters.Add(new SqlParameter("@name", ""));
            }
            else
            {
                cmd.Parameters.Add(new SqlParameter("@name", earthwatcher.Name));
            }
            cmd.Parameters.Add(new SqlParameter("@role", earthwatcher.Role));
            cmd.Parameters.Add(new SqlParameter("@prefix", passwordPrefix));
            cmd.Parameters.Add(new SqlParameter("@hash", hashedPassword));
            cmd.Parameters.Add(new SqlParameter("@country", earthwatcher.Country));
            cmd.Parameters.Add(new SqlParameter("@language", earthwatcher.Language));
            cmd.Parameters.Add(new SqlParameter("@playingCountry", earthwatcher.PlayingCountry));
            cmd.Parameters.Add(new SqlParameter("@playingRegion", earthwatcher.PlayingRegion));
            if (!string.IsNullOrEmpty(earthwatcher.NickName))
            {
                cmd.Parameters.Add(new SqlParameter("@nick", earthwatcher.NickName));
            }
            if (earthwatcher.PlayingRegion == null || earthwatcher.PlayingRegion == 0)
            {
                var           regionRepository = new RegionRepository(connection.ConnectionString);
                List <Region> regions          = regionRepository.GetByCountryCode(earthwatcher.Country);
                earthwatcher.PlayingRegion = regions.FirstOrDefault().Id;
            }

            var idParameter = new SqlParameter("@ID", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };

            cmd.Parameters.Add(idParameter);
            cmd.ExecuteNonQuery();
            var id = (int)idParameter.Value;

            earthwatcher.Id = id;
            connection.Close();
            return(earthwatcher);
        }
Esempio n. 12
0
        private void EarthwatcherRequestEarthwatcherReceived(object sender, EventArgs e)
        {
            earthwatcher    = sender as Earthwatcher;
            txtCountry.Text = earthwatcher.Country;
            txtName.Text    = string.Format("{0} on {1}", earthwatcher.FullName, land.StatusChangedDateTime.ToShortDateString());

            if (earthwatcher == null)
            {
                return;
            }
        }
Esempio n. 13
0
        public void GenerateAndUpdatePassword(Earthwatcher earthwatcher)
        {
            var prefix         = PasswordChecker.GeneratePrefix();
            var hashedPassword = PasswordChecker.GenerateHashedPassword(earthwatcher.Password, prefix);

            // store in database
            var connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["EarthwatchersConnection"].ConnectionString;
            var repos            = new EarthwatcherRepository(connectionstring);

            repos.UpdatePassword(earthwatcher, prefix, hashedPassword);
        }
        public void SetEarthwatcherAsPowerUser(int id, Earthwatcher earthwatcher)
        {
            connection.Open();
            var cmd = connection.CreateCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Earthwatcher_SetEarthwatcherAsPowerUser";
            cmd.Parameters.Add(new SqlParameter("@isPowerUser", true));
            cmd.Parameters.Add(new SqlParameter("@id", earthwatcher.Id));
            cmd.ExecuteNonQuery();
            connection.Close();
        }
Esempio n. 15
0
        public HttpResponseMessage <Earthwatcher> Get(string name)
        {
            Earthwatcher earthwatcher = earthwatcherRepository.Get(name);

            if (earthwatcher == null)
            {
                return(new HttpResponseMessage <Earthwatcher>(HttpStatusCode.NotFound));
            }
            return(new HttpResponseMessage <Earthwatcher>(earthwatcher)
            {
                StatusCode = HttpStatusCode.OK
            });
        }
Esempio n. 16
0
        private void EarthwatcherChanged(object sender, EventArgs e)
        {
            selectedEarthwatcher = sender as Earthwatcher;

            if (selectedEarthwatcher == null)
            {
                return;
            }

            //txtStatus.Text = selectedLand.LandStatus.ToString();
            txtName.Text    = selectedEarthwatcher.FullName;
            txtCountry.Text = selectedEarthwatcher.Country;
        }
Esempio n. 17
0
        public void ChangePlayingRegion(Earthwatcher earthwatcher)
        {
            connection.Open();
            var cmd = connection.CreateCommand() as SqlCommand;

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Earthwatcher_ChangePlayingRegion";
            cmd.Parameters.Add(new SqlParameter("@playingRegion", earthwatcher.PlayingRegion));
            cmd.Parameters.Add(new SqlParameter("@playingCountry", earthwatcher.PlayingCountry));
            cmd.Parameters.Add(new SqlParameter("@id", earthwatcher.Id));
            cmd.ExecuteNonQuery();
            connection.Close();
        }
Esempio n. 18
0
        void earthwatcherRequest_EarthwatcherReceived(object sender, EventArgs e)
        {
            Earthwatcher earthwatcher = sender as Earthwatcher;

            if (earthwatcher != null)
            {
                earthwatcher.Password = password;
                RootVisual            = new MainPage(earthwatcher);
            }
            else
            {
                BackToLoginPage();
            }
        }
        public bool UpdatePassword(Earthwatcher earthwatcher, string passwordPrefix, string hashedPassword)
        {
            connection.Open();
            var cmd = connection.CreateCommand() as SqlCommand;

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Earthwatcher_UpdatePassword";
            cmd.Parameters.Add(new SqlParameter("@name", earthwatcher.Name));
            cmd.Parameters.Add(new SqlParameter("@prefix", passwordPrefix));
            cmd.Parameters.Add(new SqlParameter("@hash", hashedPassword));
            cmd.ExecuteNonQuery();
            connection.Close();
            return(true);
        }
Esempio n. 20
0
 public HttpResponseMessage <decimal?> GetPresicionPercentage(Earthwatcher e, HttpRequestMessage <Earthwatcher> request)
 {
     try
     {
         decimal?percentage = landRepository.GetPrecicionDenouncePercentageByRegionId(e.PlayingRegion, e.Id);
         return(new HttpResponseMessage <decimal?>(percentage)
         {
             StatusCode = HttpStatusCode.OK
         });
     }
     catch
     {
         return(new HttpResponseMessage <decimal?>(HttpStatusCode.InternalServerError));
     }
 }
Esempio n. 21
0
        public HttpResponseMessage UpdateEarthwatcherAdmin(int id, Earthwatcher earthwatcher, HttpRequestMessage <Earthwatcher> request)
        {
            var earthwatcherDb = earthwatcherRepository.GetEarthwatcher(id);

            if (earthwatcherDb != null)
            {
                earthwatcherRepository.UpdateEarthwatcher(earthwatcher.Id, earthwatcher);
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.OK
                });
            }
            return(new HttpResponseMessage {
                StatusCode = HttpStatusCode.NotFound
            });
        }
Esempio n. 22
0
        public void GetPresicionDenouncePercentage(Earthwatcher e)
        {
            var request = new RestRequest("land/getPresicionDenouncePercentage", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.JsonSerializer = new JsonSerializer();

            request.AddBody(e);
            client.ExecuteAsync <decimal>(request, response =>
                                          Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                                    PresicionPercentageReceived(response.Content, null)
                                                                                    ));
        }
Esempio n. 23
0
        public HttpResponseMessage SetEarthwatcherAsPowerUser(Earthwatcher earthwatcher, HttpRequestMessage <Earthwatcher> request)
        {
            var earthwatcherDb = earthwatcherRepository.GetEarthwatcher(earthwatcher.Name, false);

            if (earthwatcherDb != null)
            {
                earthwatcherRepository.SetEarthwatcherAsPowerUser(earthwatcherDb.Id, earthwatcherDb);
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.OK
                });
            }
            return(new HttpResponseMessage {
                StatusCode = HttpStatusCode.NotFound
            });
        }
Esempio n. 24
0
        public HttpResponseMessage UpdateEarthWatcherRole(Earthwatcher ew, HttpRequestMessage <Earthwatcher> request)
        {
            var earthwatcherDb = earthwatcherRepository.GetEarthwatcher(ew.Name, false);

            if (earthwatcherDb != null)
            {
                earthwatcherDb.Role = ew.Role;
                earthwatcherRepository.UpdateEarthwatcher(earthwatcherDb.Id, earthwatcherDb);
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.OK
                });
            }
            return(new HttpResponseMessage {
                StatusCode = HttpStatusCode.NotFound
            });
        }
Esempio n. 25
0
        public void Confirm(int landId, int userId, ConfirmationSort confirmationSort, string username, string password)
        {
            client.Authenticator = new HttpBasicAuthenticator(username, password);

            var earthwatcher = new Earthwatcher {
                Id = userId
            };
            var request = new RestRequest("land/" + landId.ToString(CultureInfo.InvariantCulture) + @"/" + confirmationSort.ToString(), Method.PUT);

            request.AddBody(earthwatcher);
            request.RequestFormat = DataFormat.Json;
            client.ExecuteAsync(request, response =>
                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                          ConfirmationAdded(confirmationSort, null)
                                                                          ));
        }
Esempio n. 26
0
        public void ChangePlayingRegion(Earthwatcher earthwatcher)
        {
            var request = new RestRequest("earthwatchers/changeplayingregion", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.JsonSerializer = new JsonSerializer();
            request.AddBody(earthwatcher);

            client.ExecuteAsync(request, response =>
                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                          PlayingRegionChanged(
                                                                              response.StatusCode, null)
                                                                          ));
        }
Esempio n. 27
0
 public HttpResponseMessage ChangePlayingRegion(Earthwatcher earthwatcher, HttpRequestMessage <Earthwatcher> request)
 {
     try
     {
         earthwatcherRepository.ChangePlayingRegion(earthwatcher);
         return(new HttpResponseMessage {
             StatusCode = HttpStatusCode.OK
         });
     }
     catch
     {
         return(new HttpResponseMessage {
             StatusCode = HttpStatusCode.InternalServerError
         });
     }
 }
Esempio n. 28
0
        /// <summary>
        /// Busca al primer usuario que reporto esa parcela con 30 verif, le asigna los puntos, lockea la parcela y la pasa a greenpeace.
        /// </summary>
        /// <param name="land"></param>
        /// <param name="verifications"></param>
        /// <returns></returns>
        private LandMini VerificationScoring(LandMini land, int verifications)
        {
            if (verifications >= 30) //cantidad de Verifications
            {
                //Si es el usuario de Greenpeace debería buscar el owner original
                if (land.EarthwatcherId == Configuration.GreenpeaceId)
                {
                    connection.Open();

                    int?ewId = connection.Query <int>(string.Format("EXEC Land_VerificationScoring {0}, {1}", land.LandId, Configuration.GreenpeaceId)).SingleOrDefault();
                    if (ewId != null)
                    {
                        land.EarthwatcherId = Convert.ToInt32(ewId);
                    }
                    connection.Close();
                }

                //Obtengo el mail del owner original para mandarle la notificacion por mail
                connection.Open();
                string idobjMail = connection.Query <string>(string.Format("EXEC Land_VerificationScoring_2 {0}, {1}", land.LandId, Configuration.GreenpeaceId)).SingleOrDefault();
                if (idobjMail != null)
                {
                    land.Email = idobjMail;
                }
                connection.Close();

                //Obtengo el earthwatcher para agregarle los puntos
                connection.Open();
                Earthwatcher earthwatcher = connection.Query <Earthwatcher>(string.Format("EXEC Earthwatcher_GetEarthwatcher {0}", land.EarthwatcherId)).FirstOrDefault();
                connection.Close();

                //Le asigno los 2000 puntos
                var scoreRepository = new ScoreRepository(connection.ConnectionString);
                scoreRepository.PostScore(new Score(earthwatcher.Id, ActionPoints.Action.LandVerified.ToString(), ActionPoints.Points(ActionPoints.Action.LandVerified), earthwatcher.PlayingRegion, land.LandId));

                //El owner de la parcela pasa a ser Greenpeace y la parcela se lockea
                connection.Open();
                var cmd = connection.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Land_VerificationScoring_3";
                cmd.Parameters.Add(new SqlParameter("@LandId", land.LandId));
                cmd.ExecuteNonQuery();
                connection.Close();
                return(land);
            }
            return(null);
        }
Esempio n. 29
0
        public void ReassignLand(Earthwatcher earthwatcher)
        {
            client.Authenticator = new HttpBasicAuthenticator(Current.Instance.Username, Current.Instance.Password);

            var request = new RestRequest("earthwatchers/reassignland", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.JsonSerializer = new JsonSerializer();
            request.AddBody(earthwatcher);

            client.ExecuteAsync <Land>(request, response =>
                                       Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                                 LandReassigned(response.Data, null)
                                                                                 ));
        }
Esempio n. 30
0
        public void Update(Earthwatcher ew)
        {
            client.Authenticator = new HttpBasicAuthenticator(Current.Instance.Username, Current.Instance.Password);
            var request = new RestRequest("earthwatchers/updateearthwatcher", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.JsonSerializer = new JsonSerializer();
            request.AddBody(ew);

            client.ExecuteAsync(request, response =>
                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                          EarthwatcherUpdated(
                                                                              response.StatusCode, null)
                                                                          ));
        }