public async Task <OperationResult> DeleteImageAsync(DeleteProductImageInput input) { var validateResult = await _productImageValidator.ValidateDeleteProductImage(input); if (validateResult.IsSuccess) { var productDtoResult = await _productService.GetAsync(input.ProductId); if (!productDtoResult.IsSuccess) { return(OperationResultEnumerable <ProductImageDto> .Fail(productDtoResult.Validations)); } var images = await _repository.GetProductImages(productDtoResult.Result.ConvertToEntity()); images = images.Where(x => x.Id != input.ProductImageId); await _repository.UpdateProductImages(images); return(OperationResult.Success()); } else { return(OperationResult.Fail(validateResult)); } }
public async Task <ValidationResult> ValidateDeleteProductImage(DeleteProductImageInput input) { ValidationResult validationResult = new(); if (string.IsNullOrWhiteSpace(input.ProductId)) { validationResult.Messages.Add(new(nameof(DeleteProductImageInput.ProductId), "Debe ingresar el Id del Producto.")); } else { Product product = await _productRepository.GetAsync(input.ProductId); if (product is null) { validationResult.Messages.Add(new(nameof(DeleteProductImageInput.ProductId), "El producto no existe.")); } else { var images = await _productImageRepository.GetProductImages(product); var image = images.SingleOrDefault(x => x.Id == input.ProductImageId); if (image is null) { validationResult.Messages.Add(new(nameof(DeleteProductImageInput.ProductImageId), "La imagen no existe.")); } else if (product.Thumbnail == image.Image) { validationResult.Messages.Add(new(nameof(DeleteProductImageInput.ProductImageId), "No se puede eliminar la imagen principal del producto.")); } } } return(validationResult); }
public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(NotFound()); } Product product = await _productRepo.GetAsync((Guid)id); if (product == null) { return(NotFound()); } product.Images = await _prodImgRepo.GetProductImages(product.ProductID); return(View(product)); }
public async Task <ActionResult> Get([FromRoute] Guid productID) { if (Guid.Empty == productID) { return(ResponseHelper.BadRequest()); } Product product = await _productRepository.GetAsync(productID); product.ThumbnailImage = _settings.HostName + product.ThumbnailImage; product.Images = await _productImageRepository.GetProductImages(product.ProductID); foreach (ProductImage img in product.Images) { img.RelativeUrl = _settings.HostName + img.RelativeUrl; } JsonResult result = new JsonResult(product); return(result); }
public IEnumerable <ProductImage> GetProductImages() { return(ProductImageRepository.GetProductImages()); }
public async Task <IActionResult> GetProductImages() { return(Ok(await _repo.GetProductImages())); }