Exemplo n.º 1
0
        public void RemoveProduct(int productId)
        {
            Product prodDelete = _productRepository.GetAll()
                                 .Include(p => p.ProductImages)
                                 .SingleOrDefault(p => p.Id == productId);

            if (prodDelete != null)
            {
                string path = Environment.CurrentDirectory +
                              ConfigurationManager.AppSettings["ImageStore"].ToString();
                foreach (var item in prodDelete.ProductImages.ToList()) // удаляем фотки из папки
                {
                    string imageOrigin = path + "o_" + item.Name;
                    File.Delete(imageOrigin);
                    string imageSmall = path + "s_" + item.Name;
                    File.Delete(imageSmall);
                    var prodImage = _productImageRepository
                                    .GetAll(prodDelete.Id)
                                    .SingleOrDefault(pi => pi.Id == item.Id);
                    if (prodImage != null)
                    {
                        _productImageRepository.Remove(prodImage);
                        _productImageRepository.SaveChanges();
                    }
                }
                //_productImageRepository.Remove();
                //_productImageRepository.SaveChanges();
                //_productRepository.Remove(prodDelete);
                //_productRepository.SaveChanges();
            }
            ;
        }
Exemplo n.º 2
0
 public List <ProductImage> GetAll()
 {
     return(repo.GetAll().ToList());
 }
Exemplo n.º 3
0
 public IEnumerable <ProductImage> GetAll()
 {
     return(_repository.GetAll());
 }