public string Add(string name, Stream stream)
        {
            ImageUploadResult uploadResult = cloudinaryService.UploadFile(name, stream);

            return(uploadResult.StatusCode == HttpStatusCode.OK
                ? uploadResult.PublicId
                : null);
        }
        public async Task <IActionResult> Create(ProductCreateBindingModel productCreateBindingModel)
        {
            ProductServiceModel productServiceModel = new ProductServiceModel
            {
                Name     = productCreateBindingModel.Name,
                Price    = productCreateBindingModel.Price,
                Category = new CategoryServiceModel()
                {
                    Name = productCreateBindingModel.Category
                },
                Picture = await cloudinaryService.UploadFile(productCreateBindingModel.Picture)
            };

            productService.Create(productServiceModel);
            return(Redirect("/"));
        }
Ejemplo n.º 3
0
        public async Task <bool> AddPhotoToCocktail(byte[] destinationData, string filename, int cocktailId)
        {
            var cocktail = await _context.Coctails.SingleOrDefaultAsync(x => x.Id == cocktailId);

            if (cocktail != null)
            {
                var publicPhotoUrl = await _cloudinary.UploadFile(destinationData, filename);

                if (!string.IsNullOrEmpty(publicPhotoUrl))
                {
                    cocktail.PhotoUrl = publicPhotoUrl;
                    return(await _context.SaveChangesAsync() > 0);
                }
            }

            return(false);
        }