/// <summary> /// Adds the page to the database. /// </summary> /// <param name="model">The summary details for the page.</param> /// <returns>A <see cref="PageViewModel"/> for the newly added page.</returns> /// <exception cref="DatabaseException">An databaseerror occurred while saving.</exception> /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception> public PageViewModel AddPage(PageViewModel model) { try { string currentUser = _context.CurrentUsername; var currentUserId = _context.CurrentUserId; Page page = new Page(); page.Title = model.Title; page.Tags = model.CommaDelimitedTags(); page.CreatedBy = AppendIpForDemoSite(currentUser); page.CreatedOn = DateTime.UtcNow; page.ModifiedOn = DateTime.UtcNow; page.ModifiedBy = AppendIpForDemoSite(currentUser); page.ProjectStart = model.ProjectStart; page.ProjectEnd = model.ProjectEnd; page.ProjectEstimatedTime = model.ProjectEstimatedTime; page.ProjectLanguage = model.ProjectLanguage; page.ProjectStatus = model.ProjectStatus; page.ProjectAgileLifeCyclePhase = model.ProjectAgileLifeCyclePhase; page.Department = model.Department; page.FundingBoundary = model.FundingBoundary; page.orgID = model.orgID; // Double check, incase the HTML form was faked. if (_context.IsAdmin) { page.IsLocked = model.IsLocked; } PageContent pageContent = Repository.AddNewPage(page, model.Content, AppendIpForDemoSite(currentUser), DateTime.UtcNow, model.ProjectStart, model.ProjectEnd, model.ProjectEstimatedTime, model.ProjectStatus, Phase2Params.FromModel(model), model.ProjectLanguage, model.orgID); _listCache.RemoveAll(); _pageViewModelCache.RemoveAll(); // completely clear the cache to update any reciprocal links. // Update the lucene index PageViewModel savedModel = new PageViewModel(pageContent, _markupConverter); try { _searchService.Add(savedModel); } catch (SearchException) { // TODO: log } Repository.SetContributeAutoApprovedInProject(savedModel.Id, currentUserId, savedModel.orgID); return(savedModel); } catch (DatabaseException e) { throw new DatabaseException(e, "An error occurred while adding page '{0}' to the database", model.Title); } }
/// <summary> /// Clears all wiki pages from the database. /// </summary> /// <returns>Redirects to the Tools action.</returns> public ActionResult ClearPages() { TempData["SuccessMessage"] = SiteStrings.SiteSettings_Tools_ClearDatabase_Message; _pageService.ClearPageTables(); _listCache.RemoveAll(); _pageViewModelCache.RemoveAll(); return(RedirectToAction("Index")); }
public ActionResult Clear() { _pageViewModelCache.RemoveAll(); _listCache.RemoveAll(); _siteCache.RemoveAll(); TempData["CacheCleared"] = true; return(RedirectToAction("Index")); }
/// <summary> /// Adds the page to the database. /// </summary> /// <param name="model">The summary details for the page.</param> /// <returns>A <see cref="PageViewModel"/> for the newly added page.</returns> /// <exception cref="DatabaseException">An databaseerror occurred while saving.</exception> /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception> public PageViewModel AddPage(PageViewModel model) { try { string currentUser = _context.CurrentUsername; Page page = new Page(); page.Title = model.Title; page.Tags = model.CommaDelimitedTags(); page.CreatedBy = AppendIpForDemoSite(currentUser); page.CreatedOn = DateTime.UtcNow; page.ModifiedOn = DateTime.UtcNow; page.ModifiedBy = AppendIpForDemoSite(currentUser); // Double check, incase the HTML form was faked. if (_context.IsAdmin) { page.IsLocked = model.IsLocked; } PageContent pageContent = Repository.AddNewPage(page, model.Content, AppendIpForDemoSite(currentUser), DateTime.UtcNow); _listCache.RemoveAll(); _pageViewModelCache.RemoveAll(); // completely clear the cache to update any reciprocal links. // Update the lucene index PageViewModel savedModel = new PageViewModel(pageContent, _markupConverter); try { _searchService.Add(savedModel); } catch (SearchException) { // TODO: log } return(savedModel); } catch (DatabaseException e) { throw new DatabaseException(e, "An error occurred while adding page '{0}' to the database", model.Title); } }
public void RemoveAll_Should_Remove_PageViewModelCache_Keys_Only() { // Arrange CacheMock cache = new CacheMock(); cache.Add("site.blah", "xyz", new CacheItemPolicy()); ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = false }; PageViewModelCache pageCache = new PageViewModelCache(settings, cache); pageCache.Add(1, 1, new PageViewModel()); // Act pageCache.RemoveAll(); // Assert Assert.That(cache.Count(), Is.EqualTo(1)); }
public ActionResult Edit(PluginViewModel model) { TextPlugin plugin = _pluginFactory.GetTextPlugin(model.Id); if (plugin == null) { return(RedirectToAction("Index")); } // Update the plugin settings with the values from the summary plugin.Settings.IsEnabled = model.IsEnabled; foreach (SettingValue summaryValue in model.SettingValues) { SettingValue pluginValue = plugin.Settings.Values.FirstOrDefault(x => x.Name == summaryValue.Name); if (pluginValue != null) { pluginValue.Value = summaryValue.Value; } } // Update the plugin last saved date - this is important for 304 modified tracking // when the browser caching option is turned on. SiteSettings settings = SettingsService.GetSiteSettings(); settings.PluginLastSaveDate = DateTime.UtcNow; SettingsViewModel settingsViewModel = new SettingsViewModel(ApplicationSettings, settings); SettingsService.SaveSiteSettings(settingsViewModel); // Save and clear the cached settings _settingsRepository.SaveTextPluginSettings(plugin); _siteCache.RemovePluginSettings(plugin); // Clear all other caches if the plugin has been enabled or disabled. _viewModelCache.RemoveAll(); _listCache.RemoveAll(); return(RedirectToAction("Index")); }