Example #1
0
        public async Task <bool> ActualizarDatos(ProductoEntity producto)
        {
            //throw new NotImplementedException();
            var table = TablaAzure();

            var retriveOP = TableOperation
                            .Retrieve <AzProductoEntity>(
                producto.Codigo.Substring(0, 3),
                producto.Codigo
                );
            var resultado = await table.ExecuteAsync(retriveOP);

            if (resultado != null)
            {
                var p = resultado.Result as AzProductoEntity;
                p.Precio         = producto.Precio.ToString();
                p.Descripcion    = producto.Descripcion;
                p.Categoria      = producto.Categoria;
                p.PrecioImpuesto = Convert.ToString((Convert.ToDouble(producto.Precio) * 0.16) + Convert.ToDouble(producto.Precio));
                p.Nombre         = producto.Nombre;

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

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public async Task <bool> ActualizarImagen(ProductoEntity producto, object imagen)
        {
            //throw new NotImplementedException();
            var file = imagen as IFormFile;

            if (file == null)
            {
                throw new ArgumentException(nameof(imagen));
            }

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azureConStr);
            // Create a blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Get a reference to a container named "my-new-container."
            CloudBlobContainer container = blobClient.GetContainerReference("pizzaimagen");

            // Get a reference to a blob named "myblob".
            CloudBlockBlob blockBlob = container.GetBlockBlobReference($"{producto.Codigo}.jpeg");

            using (var fileStream = file.OpenReadStream())
            {
                await blockBlob.UploadFromStreamAsync(fileStream);
            }
            var url = blockBlob.Uri.AbsoluteUri;

            var table = TablaAzure();

            var retriveOP = TableOperation
                            .Retrieve <AzProductoEntity>(
                producto.Codigo.Substring(0, 3),
                producto.Codigo
                );
            var resultado = await table.ExecuteAsync(retriveOP);

            if (resultado != null)
            {
                var p = resultado.Result as AzProductoEntity;

                p.Imagen = url;


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

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        public async Task <bool> CrearProducto(ProductoEntity nuevo)
        {
            var table = TablaAzure();
            // Create the table if it doesn't exist.
            var creada = await table.CreateIfNotExistsAsync();

            var azEn = new AzProductoEntity(nuevo.Codigo);

            azEn.Descripcion    = nuevo.Descripcion;
            azEn.Nombre         = nuevo.Nombre;
            azEn.Categoria      = nuevo.Categoria;
            azEn.PrecioImpuesto = Convert.ToString((Convert.ToDouble(nuevo.Precio) * 0.16) + Convert.ToDouble(nuevo.Precio));
            azEn.Precio         = nuevo.Precio.ToString();
            azEn.Imagen         = "";

            // 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(true);
        }