public override void OnException(HttpActionExecutedContext context) { if (!PostSaveHelper.IsPostSave(context.ActionContext)) { return; } var conflict = context.Exception as ContentConflictException; if (conflict == null) { return; } _logger.Warn(conflict.Message, conflict); var display = Mapper.Map <IContent, ContentItemDisplay>((IContent)conflict.Attempted); display.UpdateDate = conflict.AttemptedDate; var changedAgo = DateTime.Now - conflict.Latest.UpdateDate; var changedByUser = _userService.GetUserById(((IContent)conflict.Latest).WriterId); // cannot use display.AddErrorNotification as it is not handled by JS properly display.Errors = new Dictionary <string, object> { { "", new[] { $"'{conflict.Attempted.Name}' was changed by user {changedByUser.Name} {changedAgo.ToHumanString()}. Please refresh the page and reapply your changes to avoid overwriting theirs." } } }; context.Response = context.Request.CreateValidationErrorResponse(display); context.Exception = null; }
public override void OnActionExecuting(HttpActionContext context) { if (!PostSaveHelper.IsPostSave(context)) { return; } var contentItem = PostSaveHelper.GetContentItemSave(context); var updateDateString = contentItem.GetUpdateDateOverrideString(); if (updateDateString == null) { return; } var updateDate = DateTime.ParseExact(updateDateString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); var content = PostSaveHelper.GetPersistedContent(contentItem); content.SetUpdateDateOverride(updateDate); _logger.DebugFormat("Set UpdateDateOverride on content {0} to '{1}'.", content.Id, updateDate); }