private async void okBtn_Click(object sender, RoutedEventArgs e)
        {
            var credit = double.Parse(moduleCreditText.Text);

            if (moduleNameText.Text.Trim() != string.Empty && credit > 0)
            {
                try
                {
                    ModuleDto moduleDto = new ModuleDto
                    {
                        ModuleName = moduleNameText.Text,
                        CourseId   = _courseId,
                        LevelId    = _levelId,
                        Credit     = credit
                    };
                    moduleDto = await _moduleController.AddModule(moduleDto);

                    moduleNameText.Text   = string.Empty;
                    moduleCreditText.Text = "0";
                    _eventAggregator.GetEvent <ModuleLoadEvent>().Publish(moduleDto);
                    MessageBox.Show("Module details saved successfully");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #2
0
        private void CopyModulesFromSourceTab(TabInfo tab, TabInfo sourceTab)
        {
            foreach (var module in sourceTab.ChildModules.Values)
            {
                if (module.IsDeleted || module.AllTabs)
                {
                    continue;
                }

                var newModule = module.Clone();

                newModule.TabID = tab.TabID;
                newModule.DefaultLanguageGuid  = Null.NullGuid;
                newModule.CultureCode          = tab.CultureCode;
                newModule.VersionGuid          = Guid.NewGuid();
                newModule.LocalizedVersionGuid = Guid.NewGuid();

                newModule.ModuleID = Null.NullInteger;
                _moduleController.InitialModulePermission(newModule, newModule.TabID, 0);
                newModule.InheritViewPermissions = module.InheritViewPermissions;

                newModule.ModuleID = _moduleController.AddModule(newModule);

                //Copy each setting to the new TabModule instance
                foreach (DictionaryEntry setting in module.ModuleSettings)
                {
                    _moduleController.UpdateModuleSetting(newModule.ModuleID, Convert.ToString(setting.Key), Convert.ToString(setting.Value));
                }

                foreach (DictionaryEntry setting in module.TabModuleSettings)
                {
                    _moduleController.UpdateTabModuleSetting(newModule.TabModuleID, Convert.ToString(setting.Key), Convert.ToString(setting.Value));
                }

                //copy permissions from source module
                foreach (ModulePermissionInfo permission in module.ModulePermissions)
                {
                    newModule.ModulePermissions.Add(new ModulePermissionInfo
                    {
                        ModuleID      = newModule.ModuleID,
                        PermissionID  = permission.PermissionID,
                        RoleID        = permission.RoleID,
                        UserID        = permission.UserID,
                        PermissionKey = permission.PermissionKey,
                        AllowAccess   = permission.AllowAccess
                    }, true);
                }

                ModulePermissionController.SaveModulePermissions(newModule);

                if (!string.IsNullOrEmpty(newModule.DesktopModule.BusinessControllerClass))
                {
                    var moduleBizClass = Reflection.CreateObject(newModule.DesktopModule.BusinessControllerClass, newModule.DesktopModule.BusinessControllerClass) as IPortable;
                    if (moduleBizClass != null)
                    {
                        var content = Convert.ToString(moduleBizClass.ExportModule(module.ModuleID));
                        if (!string.IsNullOrEmpty(content))
                        {
                            content = XmlUtils.RemoveInvalidXmlCharacters(content);
                            moduleBizClass.ImportModule(newModule.ModuleID, content, newModule.DesktopModule.Version, UserController.Instance.GetCurrentUserInfo().UserID);
                        }
                    }
                }
            }
        }