private void DeleteExistingNavigation() { var deletedModules = dbConfig.Modules.Include(m => m.Group).Include(m => m.Group.App).Where(m => m.Group.App.Id == appId && m.ModuleType == ModuleType.AutoGenerated).ToList(); dbConfig.Modules.RemoveRange(deletedModules); dbConfig.SaveChanges(); var emptyGroups = dbConfig.ModuleGroups.Include(g => g.Modules).Where(g => g.Modules.Count == 0).ToList(); dbConfig.ModuleGroups.RemoveRange(emptyGroups); dbConfig.SaveChanges(); }
/// <summary> /// Ensure that appId key presents in the configuration file. Every web application must has corresponding appId. /// </summary> /// <param name="context">An instance of <see cref="DotWebDb"/>.</param> private void EnsureApp(DotWebDb context) { if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["appId"])) { throw new ArgumentException("appId must be specified in config."); } appId = int.Parse(ConfigurationManager.AppSettings["appId"].ToString()); var app = context.Apps.SingleOrDefault(a => a.Id == appId); if (app == null) { app = new App(); // App is initiated with a default value var appName = "Sample App " + DateTime.Today.ToShortDateString(); if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["appName"])) { // If appName presents in configuration file, use it appName = ConfigurationManager.AppSettings["appName"]; } app.Id = appId; app.Name = appName; app.Description = "This app was automatically generated from DbInspector, please change the name and description appropriately."; context.Apps.Add(app); context.SaveChanges(); } schemaInfo.App = app; }