public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var brand = _context.Brands
                        .Include(e => e.Bicycles)
                        .Include($"{nameof(Lab2DbContext.Bicycles)}.{nameof(Bicycle.Sales)}")
                        .ToList().Find(e => e.Id == id);

            for (int j = 0; j < brand.Bicycles.Count; ++j)
            {
                var bic = brand.Bicycles.ElementAt(j);
                for (int k = 0; k < bic.Sales.Count; ++k)
                {
                    var sale = bic.Sales.ElementAt(k);
                    bic.Sales.Remove(sale);
                }
                _context.SaveChanges();
                brand.Bicycles.Remove(bic);
            }
            _context.SaveChanges();

            _context.Brands.Remove(brand);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var store = _context.Stores.Include(e => e.Sales).ToList().Find(e => e.Id == id);

            for (int i = 0; i < store.Sales.Count; ++i)
            {
                var sale = store.Sales.ElementAt(i);
                store.Sales.Remove(sale);
            }
            _context.SaveChanges();

            _context.Stores.Remove(store);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }