public void ActivateProfile()
        {
            var model = new ModuleProfileViewModel();

            if (TryUpdateModel<ModuleProfileViewModel>(model))
            {
                Activate(model, false);

                _notifier.Add(NotifyType.Information, T("Successfully activated profile: {0}.", model.Name));
            }
            else _notifier.Add(NotifyType.Error, T("Activating profile failed."));
        }
        public void CreateProfile()
        {
            var model = new ModuleProfileViewModel();

            if (TryUpdateModel<ModuleProfileViewModel>(model))
            {
                if (_repository.Get(p => p.Name == model.Name) == null)
                {
                    _repository.Create(new ModuleProfileRecord() { Name = model.Name });
                    _repository.Flush();

                    _notifier.Add(NotifyType.Information, T("Successfully created profile: {0}.", model.Name));
                }
                else _notifier.Add(NotifyType.Error, T("A profile with this name already exists."));
            }
            else _notifier.Add(NotifyType.Error, T("Creating profile failed: {0}.", model.Name));
        }
        public void DeleteProfile()
        {
            var model = new ModuleProfileViewModel();

            if (TryUpdateModel<ModuleProfileViewModel>(model))
            {
                _repository.Delete(_repository.Fetch(p => p.Name == model.Name).FirstOrDefault());
                _repository.Flush();

                _notifier.Add(NotifyType.Information, T("Successfully deleted profile: {0}.", model.Name));
            }
            else
            {
                if (string.IsNullOrEmpty(model.Name)) _notifier.Add(NotifyType.Error, T("No profile selected."));
                else _notifier.Add(NotifyType.Error, T("Deleting profile failed: {0}.", model.Name));
            }
        }
        private void Activate(ModuleProfileViewModel profile, bool inverse)
        {
            var modules = new JavaScriptSerializer().Deserialize<List<ModuleViewModel>>
                    (_repository.Fetch(p => p.Name == profile.Name).FirstOrDefault().Definition);

            if (inverse) _moduleProfilesService.InverseActivateProfile(modules);
            else _moduleProfilesService.ActivateProfile(modules);
        }
        public void SaveConfiguration()
        {
            var model = new ModuleProfileViewModel();

            if (TryUpdateModel<ModuleProfileViewModel>(model))
            {
                if (_repository.Get(p => p.Name == model.Name) == null)
                {
                    var installedModules = _featureManager.GetAvailableFeatures().Where(f => f.Extension.ExtensionType == "Module");
                    var enabledModules = _featureManager.GetEnabledFeatures().Where(f => f.Extension.ExtensionType == "Module");
                    foreach (var item in installedModules)
                    {
                        model.Modules.Add(new ModuleViewModel()
                        {
                            Name = item.Id,
                            Included = true,
                            Enabled = enabledModules.Contains(item)
                        });
                    }

                    try
                    {
                        _repository.Create(new ModuleProfileRecord() { Name = model.Name, Definition = new JavaScriptSerializer().Serialize(model.Modules) });
                        _repository.Flush();

                        _notifier.Add(NotifyType.Information, T("Successfully saved configuration to profile: {0}.", model.Name));
                    }
                    catch (InvalidOperationException)
                    {
                        _notifier.Add(NotifyType.Error, T("Saving configuration failed: invalid database operation."));
                    }
                }
                else _notifier.Add(NotifyType.Error, T("A profile with this name already exists."));
            }
            else _notifier.Add(NotifyType.Error, T("Saving configuration failed."));
        }