Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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
            }));
        }
Exemplo n.º 3
0
        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()
            }));
        }