public ActionResult Index(PagerParameters pagerParameters, AuditTrailOrderBy?orderBy = null) { if (!_authorizer.Authorize(Permissions.ViewAuditTrail)) { return(new HttpUnauthorizedResult()); } var pager = new Pager(_services.WorkContext.CurrentSite, pagerParameters); var filters = Filters.From(Request.QueryString, this); var pageOfData = _auditTrailManager.GetRecords(pager.Page, pager.PageSize, filters, orderBy ?? AuditTrailOrderBy.DateDescending); // If there's a filter validation error, clear the results. if (!ModelState.IsValid) { pageOfData = new PageOfItems <AuditTrailEventRecord>(Enumerable.Empty <AuditTrailEventRecord>()); } var pagerShape = New.Pager(pager).TotalItemCount(pageOfData.TotalItemCount); var filterDisplay = _auditTrailManager.BuildFilterDisplay(filters); var eventDescriptorsQuery = from c in _auditTrailManager.DescribeCategories() from e in c.Events select e; var eventDescriptors = eventDescriptorsQuery.ToDictionary(x => x.Event); var recordViewModelsQuery = from record in pageOfData let descriptor = eventDescriptors.ContainsKey(record.FullEventName) ? eventDescriptors[record.FullEventName] : AuditTrailEventDescriptor.Basic(record) select new AuditTrailEventSummaryViewModel { Record = record, EventDescriptor = descriptor, CategoryDescriptor = descriptor.CategoryDescriptor, SummaryShape = _displayBuilder.BuildDisplay(record, "SummaryAdmin"), ActionsShape = _displayBuilder.BuildActions(record, "SummaryAdmin"), }; var viewModel = new AuditTrailViewModel { Records = recordViewModelsQuery.ToArray(), Pager = pagerShape, OrderBy = orderBy ?? AuditTrailOrderBy.DateDescending, FilterDisplay = filterDisplay }; return(View(viewModel)); }
protected override DriverResult Editor(AuditTrailPart part, IUpdateModel updater, dynamic shapeHelper) { var settings = part.Settings.GetModel <AuditTrailPartSettings>(); var results = new List <DriverResult>(); if (settings.ShowAuditTrailCommentInput) { results.Add(ContentShape("Parts_AuditTrail_Comment", () => { var viewModel = new AuditTrailCommentViewModel(); if (part.ShowComment) { viewModel.Comment = part.Comment; } if (updater != null) { if (updater.TryUpdateModel(viewModel, Prefix, null, null)) { part.Comment = viewModel.Comment; } } return(shapeHelper.EditorTemplate(Model: viewModel, TemplateName: "Parts.AuditTrail.Comment", Prefix: Prefix)); })); } if (_services.Authorizer.Authorize(Permissions.ViewAuditTrail)) { if (settings.ShowAuditTrailLink) { results.Add(ContentShape("Parts_AuditTrail_Link", () => shapeHelper.Parts_AuditTrail_Link())); } if (settings.ShowAuditTrail) { results.Add(ContentShape("Parts_AuditTrail", () => { var pager = new Pager(_services.WorkContext.CurrentSite, null, null); var pageOfData = _auditTrailManager.GetRecords(pager.Page, pager.PageSize, ContentAuditTrailEventProvider.CreateFilters(part.Id, updater)); var pagerShape = shapeHelper.Pager(pager).TotalItemCount(pageOfData.TotalItemCount); var eventDescriptorsQuery = from c in _auditTrailManager.DescribeCategories() from e in c.Events select e; var eventDescriptors = eventDescriptorsQuery.ToArray(); var recordViewModelsQuery = from record in pageOfData let descriptor = eventDescriptors.FirstOrDefault(x => x.Event == record.FullEventName) where descriptor != null select new AuditTrailEventSummaryViewModel { Record = record, EventDescriptor = descriptor, CategoryDescriptor = descriptor.CategoryDescriptor, SummaryShape = _displayBuilder.BuildDisplay(record, "SummaryAdmin"), ActionsShape = _displayBuilder.BuildActions(record, "SummaryAdmin") }; var recordViewModels = recordViewModelsQuery.ToArray(); return(shapeHelper.Parts_AuditTrail(Records: recordViewModels, Pager: pagerShape)); })); } } return(Combined(results.ToArray())); }