public ActionResult <int> AddImageSecundaryOfProduct(ImageProductDto imageProduct) { return(Execute(() => { return _productService.AddImageSecundaryOfProduct(imageProduct); })); }
public int AddImageSecundaryOfProduct(ImageProductDto imageProductDto) { var imageProducts = _genericRepository.Filter <ImageProduct> (p => p.IdProduct == imageProductDto.IdProduct).ToList(); var newImageName = imageProducts.Count() + 1; var newImageProduct = ImageProduct.Create(imageProductDto.IdProduct, newImageName); _genericRepository.Add(newImageProduct); _genericRepository.SaveChanges(); return(newImageName); }
public int DeleteImageSecundaryOfProduct(ImageProductDto imageProductDto) { var imageProduct = _genericRepository.Filter <ImageProduct> (p => p.Name == imageProductDto.ImageName && p.IdProduct == imageProductDto.IdProduct && p.Active).FirstOrDefault(); if (imageProduct == null) { throw new ApplicationException(string.Format("Image {0}_{1} no encontrada" , imageProductDto.IdProduct, imageProductDto.ImageName)); } imageProduct.Desactive(); _genericRepository.SaveChanges(); return(imageProductDto.ImageName); }