public IEnumerable<Module> GetModules() { var moduleList = new List<Module>(); var moduleQuery = from modules in MainWindow.toolsetDataContext.t_ModulesTables select modules; foreach (var moduleObj in moduleQuery) { var _module = new Module(Convert.ToInt32(moduleObj.ModuleID.ToString())) { DisplayName = moduleObj.DisplayName, Name = moduleObj.Name, UUID = moduleObj.UUID, LanguageID = moduleObj.LanguageID, Details = moduleObj.Details, ProjectType = moduleObj.ProjectType, IsActive = Convert.ToBoolean(moduleObj.IsActive.ToString()) }; moduleList.Add(_module); } return moduleList; }
public static void SetModuleActiveInDatabase(Module module) { var moduleQuery = from modules in MainWindow.toolsetDataContext.t_ModulesTables select modules; foreach (var moduleObj in moduleQuery) { t_ModulesTable objModuleInactive = MainWindow.toolsetDataContext.t_ModulesTables.Single(_module => _module.ModuleID == moduleObj.ModuleID); objModuleInactive.IsActive = false; MainWindow.toolsetDataContext.SubmitChanges(); } t_ModulesTable objModuleActive = MainWindow.toolsetDataContext.t_ModulesTables.Single(_module => _module.ModuleID == module.ModuleID); objModuleActive.IsActive = true; MainWindow.toolsetDataContext.SubmitChanges(); }
public static Module GetModuleActive(IEnumerable <Module> moduleList) { //Create a new bogus module Module selected = new Module(-1); //Create a counter to make sure it is always one = 1 int counter = 0; foreach (var module in moduleList) { if (module.IsActive == true) { selected = module; counter++; } } if (counter != 1) { throw new ArgumentException("Cannot be more or less than one active module", "counter"); } return selected; }