public void UpdateBackgroundStyle(string elementId, PageSectionBackgroundStyle backgroundStyle) { var element = _document.GetElementbyId(elementId); var selectedHeight = string.Format("background-{0}", backgroundStyle).ToLower(); var heightClasses = new List <string> { "background-static", "background-parallax" }; var classAttribute = element.Attributes.SingleOrDefault(x => x.Name == "class"); foreach (var heightClass in heightClasses) { classAttribute.Value = classAttribute.Value.Replace(heightClass, selectedHeight); } }
public async Task EditBackgroundStyleAsync(int pageSectionId, PageSectionBackgroundStyle backgroundType) { var pageSection = await _context.PageSections.SingleOrDefaultAsync(x => x.PageSectionId == pageSectionId); if (pageSection == null) { return; } var document = new Document(pageSection.PageSectionBody); document.UpdateBackgroundStyle(string.Format("section-{0}", pageSectionId), backgroundType); pageSection.PageSectionBody = document.OuterHtml; await _context.SaveChangesAsync(); }