public async Task <ActionResult <Area> > DeleteArea(int id) { var area = await _context.Areas.FindAsync(id); if (area == null) { return(NotFound()); } var cosmetics = _context.Cosmetics.Where(c => c.Id_Area == id).ToList(); if (cosmetics.Count != 0) { foreach (var cosmetic in cosmetics) { var products = _context.Products.Where(p => p.Id_Cosmetics == cosmetic.Id).ToList(); if (products.Count != 0) { foreach (var product in products) { var productcolor = _context.ProductColors.Where(p => p.Id_Product == product.Id).ToList(); if (productcolor.Count != 0) { foreach (var productt in productcolor) { var prc = await _context.Products.FindAsync(productt.Id); _context.Remove(prc); await _context.SaveChangesAsync(); } } var pr = await _context.Products.FindAsync(product.Id); _context.Remove(pr); await _context.SaveChangesAsync(); } } var cs = await _context.Cosmetics.FindAsync(cosmetic.Id); _context.Remove(cs); await _context.SaveChangesAsync(); } } _context.Areas.Remove(area); await _context.SaveChangesAsync(); return(area); }
public async Task <ActionResult <Country> > DeleteCountry(int id) { var country = await _context.Countries.FindAsync(id); if (country == null) { return(NotFound()); } var firms = _context.Firms.Where(f => f.Id_Country == id).ToList(); if (firms.Count != 0) { foreach (var firm in firms) { var products = _context.Products.Where(p => p.Id_Firm == id).ToList(); if (products.Count != 0) { foreach (var product in products) { var productcolors = _context.ProductColors.Where(p => p.Id_Product == product.Id).ToList(); if (productcolors.Count != 0) { foreach (var productcolor in productcolors) { var pr = await _context.ProductColors.FindAsync(productcolor.Id); _context.Remove(pr); await _context.SaveChangesAsync(); } } var p = await _context.ProductColors.FindAsync(product.Id); _context.Remove(p); await _context.SaveChangesAsync(); } } var f = await _context.Firms.FindAsync(firm.Id); _context.Remove(f); await _context.SaveChangesAsync(); } } _context.Countries.Remove(country); await _context.SaveChangesAsync(); return(country); }
public async Task <ActionResult <_Color> > Delete_Color(int id) { var _Color = await _context.Colors.FindAsync(id); if (_Color == null) { return(NotFound()); } var productcolor = _context.ProductColors.Where(p => p.Id_Color == id).ToList(); if (productcolor.Count != 0) { foreach (var productt in productcolor) { var pr = await _context.Products.FindAsync(productt.Id); _context.Remove(pr); await _context.SaveChangesAsync(); } } _context.Colors.Remove(_Color); await _context.SaveChangesAsync(); return(_Color); }
public async Task <ActionResult <Cosmetic> > DeleteCosmetic(int id) { var cosmetic = await _context.Cosmetics.FindAsync(id); if (cosmetic == null) { return(NotFound()); } var products = _context.Products.Where(p => p.Id_Cosmetics == id).ToList(); if (products.Count != 0) { foreach (var product in products) { var productcolors = _context.ProductColors.Where(p => p.Id_Product == product.Id).ToList(); if (productcolors.Count != 0) { foreach (var productcolor in productcolors) { var pr = await _context.ProductColors.FindAsync(productcolor.Id); _context.Remove(pr); await _context.SaveChangesAsync(); } } var p = await _context.ProductColors.FindAsync(product.Id); _context.Remove(p); await _context.SaveChangesAsync(); } } _context.Cosmetics.Remove(cosmetic); await _context.SaveChangesAsync(); return(cosmetic); }