public ActionResult SaveProfile()
        {
            var model = new ProfileListViewModel();

            if (TryUpdateModel<ProfileListViewModel>(model))
            {
                var profile = _repository.Fetch(p => p.Name == model.Current.Name).FirstOrDefault();
                var included = model.Current.Modules.Where(m => m.Included);
                profile.Definition = new JavaScriptSerializer().Serialize(included);

                try
                {
                    _repository.Create(profile);
                    _repository.Flush();

                    _notifier.Add(NotifyType.Information, T("Successfully saved profile: {0}.", model.Current.Name));
                }
                catch (InvalidOperationException)
                {
                    _notifier.Add(NotifyType.Error, T("Saving profile failed: invalid operation."));
                }
            }
            else _notifier.Add(NotifyType.Error, T("Saving profile failed.", model.Current.Name));

            return RedirectToAction("Index", new { profileName = model.Current.Name });
        }
        public ActionResult Index(string profileName = "")
        {
            var profilesData = _repository.Table.ToList();
            var model = new ProfileListViewModel();

            if (profilesData != null || profilesData.Count > 0)
            {
                foreach (var item in profilesData) model.ProfileNames.Add(item.Id, item.Name);

                if (!string.IsNullOrEmpty(profileName) && model.ProfileNames.ContainsValue(profileName))
                {
                    model.Current = new ModuleProfileViewModel()
                    {
                        Name = profileName,
                        Modules = (new JavaScriptSerializer().Deserialize<List<ModuleViewModel>>
                        (profilesData.Find(p => p.Name == profileName).Definition)
                            ?? new List<ModuleViewModel>()).OrderBy(m => m.Enabled).ThenBy(m => m.Name).ToList()
                    };

                    var installedModulesIds = _featureManager.GetAvailableFeatures().Where(f => f.Extension.ExtensionType == "Module").OrderBy(m => m.Id).Select(m => m.Id);
                    model.Current.Modules.RemoveAll(m => !installedModulesIds.Contains(m.Name));
                    foreach (var item in installedModulesIds)
                    {
                        if (model.Current.Modules.Find(m => m.Name == item) == null)
                        {
                            model.Current.Modules.Add(new ModuleViewModel() { Name = item });
                        }
                    }

                    var enabledModulesIds = _featureManager.GetEnabledFeatures().Where(f => f.Extension.ExtensionType == "Module").Select(m => m.Id);
                    foreach (var item in model.Current.Modules) item.State = enabledModulesIds.Contains(item.Name);
                }
            }

            return View(model);
        }