public async Task CreateAnimalImageAsync(AddImagesInputModel input, string userId, int animalId)
        {
            foreach (var image in input.Images)
            {
                var extension = Path.GetExtension(image.FileName);

                if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
                {
                    throw new Exception($"Invalid image extension {extension}");
                }

                var imageUrl = await this.cloudinaryService.UploadAsync(this.cloudinary, image);

                var tempImage = new AnimalImage
                {
                    UserId   = userId,
                    AnimalId = animalId,
                    ImageUrl = imageUrl,
                };

                await this.animalImagesRepository.AddAsync(tempImage);
            }

            await this.animalImagesRepository.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public IActionResult AddImages(int id)
        {
            var model = new AddImagesInputModel {
                ProductId = id
            };

            return(this.View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddImages(AddImagesInputModel input)
        {
            foreach (var image in input.URL)
            {
                if (string.IsNullOrEmpty(image) || !new UrlAttribute().IsValid(image))
                {
                    continue;
                }

                var imageModel = new ImageViewModel()
                {
                    ProductId = input.ProductId, Url = image
                };
                await this.productService.AddProductImageAsync(imageModel);
            }

            return(this.Redirect("/Products/ProductImages/" + input.ProductId));
        }
        public async Task <IActionResult> AddImages(AddImagesInputModel input, int id)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            try
            {
                await this.animalService.CreateAnimalImageAsync(input, user.Id, id);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View(input));
            }

            return(this.Redirect("/Animal/All"));
        }