public static ContentViewModel WithEditedBy(this ContentViewModel c) { var editedBy = ContentHistoryApi.SelectByContentId(c.Id).Select(ch => ch.ChangedByUserId).Distinct().ToList(); if (!editedBy.Contains(c.UserId)) { editedBy.Add(c.UserId); } c.EditedBy = editedBy.Select(u => UserApi.GetById(u)).ToList(); return(c); }
public static void Update(int id, string title, string body, string htmlBody, int userId) { var currentVal = Select(id); if (currentVal.Body != body) { ContentHistoryApi.Insert("Body", currentVal, userId); } if (currentVal.Title != title) { ContentHistoryApi.Insert("Title", currentVal, userId); } Execute($@"UPDATE [dbo].[Content] SET Title = '{title.SqlEncode()}', Body = '{body.SqlEncode()}', HtmlBody = '{htmlBody.SqlEncode()}' WHERE id = {id}"); }
public IActionResult Show(int id) { var contentController = new ContentManager(); var content = contentController.Get(id); ViewData["Title"] = content.Title; var answer = content.Children.FirstOrDefault(); if (answer != null) { content.Children = new List <ContentViewModel> { answer }; } content.History = ContentHistoryApi.SelectByContentId(id); return(View(new ContentPageModel() { Content = content })); }
public IActionResult Compare(int id) { var content = ContentApi.Select(id); var oldContent = ContentApi.Select(id); var changeSets = ContentHistoryApi.SelectByContentId(id, DateTime.Now.AddDays(-1), DateTime.Now).OrderBy(c => c.Changed); foreach (var property in oldContent.GetType().GetProperties()) { if (changeSets.Any(c => c.ChangedField == property.Name)) { var oldVal = changeSets.First(c => c.ChangedField == property.Name).OldValue; property.SetValue(oldContent, oldVal); } } oldContent.HtmlBody = Site.Markdown.Encode(oldContent.Body); return(View(new Comparison { Old = oldContent, New = content, ChangeSets = changeSets.Select(cs => new ContentHistoryViewModel(cs)).ToList() })); }