public LandMini GetFreeLand(string baseCamp, string geohexKey)
        {
            //Primero asigno un basecamp
            var             basecampRepository = new BasecampRepository(connection.ConnectionString);
            List <Basecamp> basecamps          = basecampRepository.GetByBasecamp(baseCamp);
            bool            usedLand           = false;
            string          newgeohexKey       = null;

            if (basecamps != null && basecamps.Count > 0)
            {
                int    total      = basecamps.Sum(x => x.Probability);
                int    acumprob   = 0;
                Random rand       = new Random();
                int    r          = rand.Next(1, total + 1);
                int    basecampid = 0;
                foreach (var basecamp in basecamps)
                {
                    acumprob += basecamp.Probability;
                    if (r < acumprob)
                    {
                        basecampid = basecamp.Id;
                        break;
                    }
                }

                if (basecampid != 0)
                {
                    var sql = "Earthwatcher_GetFreeLand";
                    connection.Open();
                    var cmd = connection.CreateCommand() as SqlCommand;
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@BasecampDetailId", basecampid);
                    cmd.Parameters.AddWithValue("@TutorLandId", Configuration.TutorLandId);
                    cmd.Parameters.AddWithValue("@GeoHexKey", geohexKey);

                    var reader    = cmd.ExecuteReader();
                    var hasResult = reader.Read();
                    int landId    = 0;
                    if (hasResult)
                    {
                        landId       = reader.GetInt32(0);
                        newgeohexKey = reader.GetString(2);
                        usedLand     = reader.GetBoolean(3);
                    }
                    connection.Close();
                    return(new LandMini {
                        GeohexKey = newgeohexKey, IsUsed = usedLand, Id = landId
                    });
                }
            }

            return(null);
        }
        public LandMini GetFreeLandByEarthwatcherId(string baseCamp, int earthwatcherId)
        {
            //Primero asigno un basecamp
            var basecampRepository = new BasecampRepository(connection.ConnectionString);
            List<Basecamp> basecamps = basecampRepository.GetByBasecamp(baseCamp);
            bool usedLand = false;
            string newgeohexKey = null;
            if (basecamps != null && basecamps.Count > 0)
            {
                int total = basecamps.Sum(x => x.Probability);
                int acumprob = 0;
                Random rand = new Random();
                int r = rand.Next(1, total + 1);
                int basecampid = 0;
                foreach (var basecamp in basecamps)
                {
                    acumprob += basecamp.Probability;
                    if (r < acumprob)
                    {
                        basecampid = basecamp.Id;
                        break;
                    }
                }

                if (basecampid != 0)
                {
                    try
                    {
                        var sql = "Earthwatcher_GetFreeLandByEarthwatcherId";
                        connection.Open();
                        var cmd = connection.CreateCommand() as SqlCommand;
                        cmd.CommandText = sql;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@BasecampDetailId", basecampid);
                        cmd.Parameters.AddWithValue("@TutorLandId", Configuration.TutorLandId);
                        cmd.Parameters.AddWithValue("@EarthwatcherId", earthwatcherId);

                        var reader = cmd.ExecuteReader();
                        var hasResult = reader.Read();
                        int landId = 0;
                        if (hasResult)
                        {
                            landId = reader.GetInt32(0);
                            newgeohexKey = reader.GetString(2);
                            usedLand = reader.GetBoolean(3);
                        }
                        connection.Close();
                        return new LandMini { GeohexKey = newgeohexKey, IsUsed = usedLand, Id = landId };
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Ha ocurrido una excepcion :", ex); //TODO: HANDLER DE ESTA EXCEPTION
                    }
                }

            }

            return null;
        }