public bool DeletePage(Guid id) { using var context = new DeviserDbContext(_dbOptions); //Page var dbPage = GetDeletedPage(id); if (dbPage != null) { context.Page.Remove(dbPage); } //PageTranslation var dbPageTranslation = context.PageTranslation .Where(p => p.PageId == id); context.PageTranslation.RemoveRange(dbPageTranslation); //PagePermission var dbPagePermission = context.PagePermission .Where(p => p.PageId == id); context.PagePermission.RemoveRange(dbPagePermission); //PageContent var dbPageContent = context.PageContent .Where(p => p.PageId == id); context.PageContent.RemoveRange(dbPageContent); //ContentPermission foreach (var pageContent in dbPageContent) { var dbContentPermission = context.ContentPermission .Where(p => p.PageContentId == pageContent.Id); if (dbContentPermission != null) { context.ContentPermission.RemoveRange(dbContentPermission); } //PageContentTranslation var dbPageContentTranslation = context.PageContentTranslation .Where(p => p.PageContentId == pageContent.Id); context.PageContentTranslation.RemoveRange(dbPageContentTranslation); } //PageModule var dbPageModule = context.PageModule .Where(p => p.PageId == id); context.PageModule.RemoveRange(dbPageModule); //ModulePermission foreach (var pageModule in dbPageModule) { var dbModulePermission = context.ModulePermission .Where(p => p.PageModuleId == pageModule.Id) .ToList(); context.ModulePermission.RemoveRange(dbModulePermission); } var adminPages = context.AdminPage.Where(ap => ap.PageId == id); context.RemoveRange(adminPages); context.SaveChanges(); return(true); }