public ActionResult Edit(StaticContentType contentType) { CheckIfSiteAdmin(); var staticContentViewModel = new StaticContentViewModel(); var staticContent = _staticContentService.GetStaticContent(contentType); staticContentViewModel.Content = staticContent.Content; try { // Format the HTML returned by Telerik control so that indented HTML will be shown in HTML editor. staticContentViewModel.Content = XElement.Parse(staticContentViewModel.Content).ToString(); } catch (XmlException) { try { // In case if the HTML doesn't have a root, add a <p> tag as wrapper. staticContentViewModel.Content = XElement.Parse(string.Format(CultureInfo.CurrentCulture, "<p>{0}</p>", staticContentViewModel.Content)).ToString(); } catch (XmlException) { // Consume any other Xml exception with parsing and try to load the string as is. // There could be problem like the text is not a valid XML. } } return View("Save", staticContentViewModel); }
/// <summary> /// Gets static content from the DB /// </summary> /// <param name="staticContentType">static Content Type</param> /// <returns>static content object</returns> public StaticContentDetails GetStaticContent(StaticContentType staticContentType) { Expression<Func<StaticContent, bool>> condition = (staticContent) => staticContent.StaticContentType.TypeID == (int)staticContentType && staticContent.IsDeleted == false; var content = _staticContentRepository.GetItem(condition); var staticContentDetails = new StaticContentDetails(); Mapper.Map(content, staticContentDetails); return staticContentDetails; }
public void Render(StaticContentType staticContentType) { try { var staticContent = _staticContentService.GetStaticContent(staticContentType); PartialView("StaticContentView", staticContent).ExecuteResult(ControllerContext); } catch (Exception) { // Consume the exception and render rest of the views in the page. // TODO: Log the exception? } }