Esempio n. 1
0
        public IActionResult Delete(int id)
        {
            var flyer    = _flyerRepository.GetById(id);
            var products = _productRepository.GetByCondition(p => p.Flyer.Id == id);

            foreach (var prodcut in products)
            {
                _productRepository.Delete(prodcut.Id);
            }
            var merchant = _merchantRepository.GetByCondition(m => m.Flyers.Contains(flyer)).FirstOrDefault();

            if (merchant != null)
            {
                var productInMerchant = _productRepository.GetProductInMerchant(merchant.Id);
                if (productInMerchant.Count == 0)
                {
                    var categories = _categoryReposity.GetCategoryByMerchant(merchant);
                    foreach (var category in categories)
                    {
                        _categoryReposity.Delete(category.Id);
                    }
                    _merchantRepository.Delete(merchant.Id);
                }
            }
            _flyerRepository.Delete(id);
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
 // GET: Flyer/Details/5
 public ActionResult Delete(int id)
 {
     _flyerRepository.Delete(id);
     return(RedirectToAction("Index"));
 }