From ac3d595709e712eb5270d82e9a8e8cf2a604608d Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Mon, 1 Aug 2016 12:18:00 +0200 Subject: [PATCH] #48 - add content containing form to event args --- .../FormEditor/Events/FormEditorCancelEventArgs.cs | 13 ++++++++++--- .../FormEditor/Events/FormEditorEventArgs.cs | 7 ++++++- Source/Solution/FormEditor/FormModel.cs | 12 ++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Source/Solution/FormEditor/Events/FormEditorCancelEventArgs.cs b/Source/Solution/FormEditor/Events/FormEditorCancelEventArgs.cs index 0c0012e..e8c2b05 100644 --- a/Source/Solution/FormEditor/Events/FormEditorCancelEventArgs.cs +++ b/Source/Solution/FormEditor/Events/FormEditorCancelEventArgs.cs @@ -1,12 +1,19 @@ -using System.Collections.Generic; -using System.ComponentModel; -using FormEditor.Fields; +using System.ComponentModel; +using Umbraco.Core.Models; namespace FormEditor.Events { public class FormEditorCancelEventArgs : CancelEventArgs { + public FormEditorCancelEventArgs(IPublishedContent content) + { + Content = content; + } + // if Cancel is set to true, use this property to describe the error to the user public string ErrorMessage { get; set; } + + // the content that contains the form + public IPublishedContent Content { get; private set; } } } \ No newline at end of file diff --git a/Source/Solution/FormEditor/Events/FormEditorEventArgs.cs b/Source/Solution/FormEditor/Events/FormEditorEventArgs.cs index 74e3374..0ec9ff8 100644 --- a/Source/Solution/FormEditor/Events/FormEditorEventArgs.cs +++ b/Source/Solution/FormEditor/Events/FormEditorEventArgs.cs @@ -1,15 +1,20 @@ using System; +using Umbraco.Core.Models; namespace FormEditor.Events { public class FormEditorEventArgs : EventArgs { - public FormEditorEventArgs(Guid rowId) + public FormEditorEventArgs(Guid rowId, IPublishedContent content) { RowId = rowId; + Content = content; } // the ID of the persisted data in the storage index public Guid RowId { get; private set; } + + // the content that contains the form + public IPublishedContent Content { get; private set; } } } \ No newline at end of file diff --git a/Source/Solution/FormEditor/FormModel.cs b/Source/Solution/FormEditor/FormModel.cs index ae9d3ee..a3ec663 100644 --- a/Source/Solution/FormEditor/FormModel.cs +++ b/Source/Solution/FormEditor/FormModel.cs @@ -140,7 +140,7 @@ public bool CollectSubmittedValues(IPublishedContent content, bool redirect = tr } // we're about to add data to the index - let's run the before add to index event handler - var beforeAddToIndexErrorMessage = RaiseBeforeAddToIndex(); + var beforeAddToIndexErrorMessage = RaiseBeforeAddToIndex(content); if(beforeAddToIndexErrorMessage != null) { // the event was cancelled - use the validation system to pass the error message back to the user @@ -164,7 +164,7 @@ public bool CollectSubmittedValues(IPublishedContent content, bool redirect = tr } // tell everyone that something was added - RaiseAfterAddToIndex(rowId); + RaiseAfterAddToIndex(rowId, content); SetFormSubmittedCookie(content); @@ -446,13 +446,13 @@ private string FormatForIndexAndSanitize(FieldWithValue field, IPublishedContent return doc.DocumentNode.InnerText; } - private string RaiseBeforeAddToIndex() + private string RaiseBeforeAddToIndex(IPublishedContent content) { if(BeforeAddToIndex != null) { try { - var cancelEventArgs = new FormEditorCancelEventArgs(); + var cancelEventArgs = new FormEditorCancelEventArgs(content); BeforeAddToIndex.Invoke(this, cancelEventArgs); if(cancelEventArgs.Cancel) { @@ -469,13 +469,13 @@ private string RaiseBeforeAddToIndex() return null; } - private void RaiseAfterAddToIndex(Guid rowId) + private void RaiseAfterAddToIndex(Guid rowId, IPublishedContent content) { if(AfterAddToIndex != null) { try { - AfterAddToIndex.Invoke(this, new FormEditorEventArgs(rowId)); + AfterAddToIndex.Invoke(this, new FormEditorEventArgs(rowId, content)); } catch(Exception ex) {