Ejemplo n.º 1
0
        public async Task <T> UpdateAsync(T model, IFormFile file)
        {
            var oldProduct = await GetByIdAsync(model.Id);

            model.ImgUrl      = oldProduct.ImgUrl;
            model.ImgPulbicId = oldProduct.ImgPulbicId;

            if (file != null)
            {
                var url = await cloudinaryService.UploadImageAsync(file);

                model.ImgUrl      = url.Url;
                model.ImgPulbicId = url.PublicId;
                await cloudinaryService.RemoveImageAsync(oldProduct.ImgPulbicId);
            }

            return(await mongoDb.ReplaceOneAsync(model));
        }