public async Task <PedidoModel> LeerPedido(string id)
        {
            var table = TablaAzure();

            TableOperation retrieveOperation = TableOperation.Retrieve <PedidoAzEntity>(
                PedidoAzEntity.PartitionFromRowId(id),
                id
                );

            // Execute the retrieve operation.
            TableResult retrievedResult = await table.ExecuteAsync(retrieveOperation);

            // Print the phone number of the result.
            if (retrievedResult.Result != null)
            {
                var az = retrievedResult.Result as PedidoAzEntity;
                return(new PedidoModel()
                {
                    PedidoId = az.PedidoId,
                    Cliente = az.Cliente,
                    FechaPedido = az.FechaPedido,
                    Estado = az.Estado,
                    Productos = az.Productos,
                    Referencia = az.Referencia
                });
            }
            return(null);
        }
        public async Task <bool> ActualizarReferencia(string id, string nuevoEstado, string referencia)
        {
            PedidoModel pedido = await LeerPedido(id);

            var table = TablaAzure();

            var retriveOP = TableOperation
                            .Retrieve <PedidoAzEntity>(
                PedidoAzEntity.PartitionFromRowId(pedido.PedidoId),
                pedido.PedidoId
                );
            var resultado = await table.ExecuteAsync(retriveOP);

            if (resultado != null)
            {
                var p = resultado.Result as PedidoAzEntity;
                p.Estado     = nuevoEstado;
                p.Referencia = referencia;

                var upOp = TableOperation.Replace(p);
                await table.ExecuteAsync(upOp);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <List <PedidoModel> > LeerPedidosPorFecha(DateTime fecha)
        {
            var tabla = TablaAzure();

            var particion = PedidoAzEntity.PartitionKeyFromFecha(fecha);
            TableQuery <PedidoAzEntity> query = new TableQuery <PedidoAzEntity>()
                                                .Where(
                TableQuery.GenerateFilterCondition("PartitionKey",
                                                   QueryComparisons.Equal, particion));

            // Print the phone number of the result.
            var token = new TableContinuationToken();
            var list  = new List <PedidoModel>();

            foreach (PedidoAzEntity az in await tabla.ExecuteQuerySegmentedAsync(query, token))
            {
                list.Add(new PedidoModel()
                {
                    PedidoId          = az.PedidoId,
                    Cliente           = az.Cliente,
                    FechaPedido       = az.FechaPedido,
                    CorreoElectronico = az.CorreoElectronico,
                    Estado            = az.Estado,
                    Productos         = az.Productos,
                    Referencia        = az.Referencia
                });
            }
            return(list);
        }
        public async Task <string> IniciarPedido(PedidoModel nuevoPedido)
        {
            var table = TablaAzure();
            // Create the table if it doesn't exist.
            var creada = await table.CreateIfNotExistsAsync();

            var azEn = new PedidoAzEntity(nuevoPedido.FechaPedido, nuevoPedido.CorreoElectronico);

            //azEn.PedidoId=nuevoPedido.PedidoId;
            azEn.Cliente           = nuevoPedido.Cliente;
            azEn.Productos         = nuevoPedido.Productos;
            azEn.FechaPedido       = nuevoPedido.FechaPedido;
            azEn.Estado            = "No Pagado";
            azEn.Referencia        = "Vacio";
            azEn.CorreoElectronico = nuevoPedido.CorreoElectronico;

            // Create the TableOperation object that inserts the customer entity.
            TableOperation insertOperation = TableOperation.Insert(azEn);

            // Execute the insert operation.
            var x = await table.ExecuteAsync(insertOperation);

            return(azEn.RowKey);
        }