public async Task <bool> BorrarFraseGlobal(string partitionKey, int no_frase)
        {
            bool response = false; int phrase_number = 0, NoFrasesAdministrador = 0;
            int  NoDigitosAnterior = 0, NoDigitosActual = 0, diferenciaNoDigits = 0;
            TableQuery <FraseGlobalEntity> tableQuery = new TableQuery <FraseGlobalEntity>();
            TableContinuationToken         continuationToken = new TableContinuationToken();

            foreach (FraseGlobalEntity fraseGlobalEntity in await cloudTableFG.ExecuteQuerySegmentedAsync(tableQuery, continuationToken))
            {
                phrase_number = GetPhraseNumberByRowKey(fraseGlobalEntity.RowKey);
                if (fraseGlobalEntity.PartitionKey.Equals(partitionKey) && phrase_number == no_frase)
                {
                    TableOperation RetrieveOperation = TableOperation.Retrieve <FraseGlobalEntity>(partitionKey, fraseGlobalEntity.RowKey);
                    TableResult    RetrievedResult   = await cloudTableFG.ExecuteAsync(RetrieveOperation);

                    FraseGlobalEntity EntityToDelete  = (FraseGlobalEntity)RetrievedResult.Result;
                    TableOperation    DeleteOperation = TableOperation.Delete(EntityToDelete);
                    await cloudTableFG.ExecuteAsync(DeleteOperation);

                    NoFrasesAdministrador = GetAdminPhrasesNumberByPartitionKey(partitionKey).Result;
                    NoDigitosAnterior     = NoFrasesAdministrador.ToString().Length;
                    NoDigitosActual       = (NoFrasesAdministrador - 1).ToString().Length;
                    diferenciaNoDigits    = NoDigitosAnterior - NoDigitosActual;
                    if (diferenciaNoDigits == 1)
                    {
                        AjustaFrasesGlobalesRowKey(partitionKey);
                    }
                    response = true; break;
                }
            }
            return(response);
        }
        public async void AjustaFrasesGlobalesRowKey(string partitionKey)
        {
            List <FraseGlobal> ListaFrasesGlobales = GetFrasesGlobalesAdministrador(partitionKey).Result;
            string             rowKeyAjustado; int NoFrase = 1; int NoFrases = ListaFrasesGlobales.Count;
            int zeroCounter = Convert.ToString(NoFrases).Length - Convert.ToString(NoFrase).Length;

            for (int i = 0; i < NoFrases; i++)
            {
                for (int j = 9; j <= i; j = (j + 1) * 10 - 1)
                {
                    if (j == i)
                    {
                        zeroCounter = zeroCounter - 1;
                    }
                }
                rowKeyAjustado = "Frase." + getNZeros(zeroCounter) + NoFrase;
                TableOperation RetrieveOperation = TableOperation.Retrieve <FraseGlobalEntity>(partitionKey, ListaFrasesGlobales[i].nombre_frase);
                TableResult    RetrievedResult   = await cloudTableFG.ExecuteAsync(RetrieveOperation);

                FraseGlobalEntity EntityToDelete  = (FraseGlobalEntity)RetrievedResult.Result;
                TableOperation    DeleteOperation = TableOperation.Delete(EntityToDelete);
                await cloudTableFG.ExecuteAsync(DeleteOperation);

                FraseGlobalEntity EntityToCreate = new FraseGlobalEntity(partitionKey, rowKeyAjustado);
                EntityToCreate.valor_frase = ListaFrasesGlobales[i].valor_frase;
                TableOperation InsertOperation = TableOperation.Insert(EntityToCreate);
                await cloudTableFG.ExecuteAsync(InsertOperation); NoFrase++;
            }
        }
        public async Task <bool> ActualizarFraseGlobal(string partitionKey, int no_frase, string valor_frase)
        {
            bool response = false; int phrase_number = 0;
            TableQuery <FraseGlobalEntity> tableQuery = new TableQuery <FraseGlobalEntity>();
            TableContinuationToken         continuationToken = new TableContinuationToken();

            foreach (FraseGlobalEntity fraseGlobalEntity in await cloudTableFG.ExecuteQuerySegmentedAsync(tableQuery, continuationToken))
            {
                phrase_number = GetPhraseNumberByRowKey(fraseGlobalEntity.RowKey);
                if (fraseGlobalEntity.PartitionKey.Equals(partitionKey) && phrase_number == no_frase)
                {
                    TableOperation RetrieveOperation = TableOperation.Retrieve <FraseGlobalEntity>(partitionKey, fraseGlobalEntity.RowKey);
                    TableResult    RetrievedResult   = await cloudTableFG.ExecuteAsync(RetrieveOperation);

                    FraseGlobalEntity EntityToUpdate = (FraseGlobalEntity)RetrievedResult.Result;
                    EntityToUpdate.valor_frase = valor_frase;
                    TableOperation UpdateOperation = TableOperation.Replace(EntityToUpdate);
                    await cloudTableFG.ExecuteAsync(UpdateOperation);

                    response = true; break;
                }
            }
            return(response);
        }
        public async Task <bool> CrearFraseGlobal(FraseGlobal fraseGlobal)
        {
            bool response = false; int NoFrasesAdministrador = 0;
            int  NoDigitosAnterior = 0, NoDigitosActual = 0, diferenciaNoDigits = 0;

            try {
                NoFrasesAdministrador = GetAdminPhrasesNumberByPartitionKey(fraseGlobal.email_administrador).Result;
                NoDigitosAnterior     = NoFrasesAdministrador.ToString().Length;
                if (NoFrasesAdministrador == 0)
                {
                    NoFrasesAdministrador = 1;
                }
                else
                {
                    NoFrasesAdministrador += 1;
                };
                FraseGlobalEntity fraseGlobalEntity = new FraseGlobalEntity(fraseGlobal.email_administrador, "Frase." + NoFrasesAdministrador);
                fraseGlobalEntity.valor_frase = fraseGlobal.valor_frase;
                TableOperation insertOperation = TableOperation.Insert(fraseGlobalEntity);
                await cloudTableFG.ExecuteAsync(insertOperation);

                NoDigitosActual    = NoFrasesAdministrador.ToString().Length;
                diferenciaNoDigits = NoDigitosActual - NoDigitosAnterior;
                if (diferenciaNoDigits == 1)
                {
                    AjustaFrasesGlobalesRowKey(fraseGlobal.email_administrador);
                }
                response = true;
            }
            catch (Exception exception) {
                await Console.Out.WriteLineAsync(exception.Message);

                response = false;
            }
            return(response);
        }