public async Task <IActionResult> DeleteConfirmed(int id) { var sellerAccount = await _context.SellerAccounts .Include(s => s.Account) .Where(s => s.SellerId == id) .ToListAsync(); var sellListing = _context.SellListings .Include(s => s.PriceTrend) .Include(s => s.Seller) .Include(s => s.Seller.Account) .Where(s => s.Seller.SellerId == id); foreach (var item in sellerAccount) { if (sellListing != null) { MyListingsController myListings = new MyListingsController(_context, _hostEnvironment); foreach (var sitem in sellListing) { sitem.SellerId = 1; sitem.Display = false; _context.SellListings.Update(sitem); } } var tradeListing = _context.TradeListings .Include(t => t.Seller) .Include(t => t.Seller.Account) .Where(t => t.Seller.SellerId == id); if (tradeListing != null) { MyListingsController myListings = new MyListingsController(_context, _hostEnvironment); foreach (var titem in tradeListing) { titem.SellerId = 1; titem.Display = false; _context.TradeListings.Update(titem); } } var sellerReview = _context.SellerReviews .Include(s => s.Seller) .Include(s => s.Seller.Account) .Where(s => s.Seller.SellerId == id); if (sellerReview != null) { SellerReviewsController sellerReviews = new SellerReviewsController(_context); foreach (var ritem in sellerReview) { await sellerReviews.DeleteConfirmed(ritem.SellerReviewId); } } _context.SellerAccounts.Remove(item); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> DeleteConfirmed(int id) { var account = await _context.Accounts.FindAsync(id); var serviceListing = await _context.ServiceListings .Include(s => s.Account) .Where(m => m.AccountId == id) .ToListAsync(); var sellerAccount = await _context.SellerAccounts .Include(s => s.Account) .Where(s => s.AccountId == id) .ToListAsync(); var accountPurchases = await _context.AccountPurchases .Include(a => a.Account) .Include(a => a.Cart) .Where(m => m.AccountId == id) .ToListAsync(); var cartContext = await _context.Cart .Where(m => m.AccountId == id) .ToListAsync(); var rewardContext = await _context.Rewards .Include(r => r.Account) .Where(m => m.AccountId == id) .ToListAsync(); if (serviceListing != null) { MyListingsController myListings = new MyListingsController(_context, _hostEnvironment); foreach (var item in serviceListing) { await myListings.DeleteConfirmedService(item.ServiceListingId); } } if (sellerAccount != null) { SellerAccountsController sellerAccounts = new SellerAccountsController(_context, _hostEnvironment); foreach (var item in sellerAccount) { await sellerAccounts.DeleteConfirmed(item.SellerId); } } if (accountPurchases != null) { AccountPurchasesController purchasesController = new AccountPurchasesController(_context); foreach (var item in accountPurchases) { await purchasesController.DeleteConfirmed(item.AccountPurchaseId); } } if (cartContext != null) { CartsController cartsController = new CartsController(_context, _hostEnvironment); foreach (var item in cartContext) { await cartsController.DeleteCart(item.CartId); } } if (rewardContext != null) { RewardsController rewardsController = new RewardsController(_context, _hostEnvironment); foreach (var item in rewardContext) { await rewardsController.DeleteConfirmed(item.RewardId); } } _context.Accounts.Remove(account); await _context.SaveChangesAsync(); await Logout(); return(RedirectToAction("Index", "Home")); }