Prevent submission if unable to log

Vote:
 

For some of our forms we have a special LogBlock. When a LogBlock exists I want to log something to the db. If that logging is sucessfull the form submission can continue.

However, if logging fails, I want to abort form submission with an error. Any ideas on how to achieve this?

#188821
Mar 05, 2018 10:23
Vote:
 

You can override PerformDataSubmit method in DataSubmissionService then do your bussiness there. If everything is ok, call the base to do rest of submission process.

#188823
Mar 05, 2018 10:40
Vote:
 

That sounds like a very valid strategy.  Newbish question but how do I convert the rawSubmittedData to something like SubmissionFriendlyNameInfos available in an Actor. Need to know what types was sent.

Also, how should I structure a "faulty" reponse with SubmitActionResult ?

return new SubmitActionResult()
            {
                IsSuccess = false,
                Message = "Something went wrong",
                
            };

Also, I need to abort any Actors. Doesn't seem to do that.

What about using the "Instance_FormsSubmitting", could that somehow about the submission.

#188834
Edited, Mar 05, 2018 12:59
Vote:
 

You can get friendly name mapping for a form like below:

var friendlyNames = _formRepository.Service.GetDataFriendlyNameInfos(formIden);

Use BuildReturnResultForSubmitAction to return error response, it might help.

When something went wrong with your submission you should NOT call base.PerformDataSubmit, this will prevent actors executed.

#188854
Mar 06, 2018 3:26
Vote:
 

And how do I get the formIdentity, it is not exposed as parameters to that method?

Also, I tried subscribing to:

FormsEvents.Instance.FormsSubmitting

and then

if something went wrong

private void Instance_FormsSubmitting(object sender, FormsEventArgs e) {
var myLogService= ServiceLocator.Current.GetInstance<MyLogService>();
var formsSubmittingEventArgs = e as FormsSubmittingEventArgs;
// The event fires before the data is submitted so there is an opportunity to interact here

if(!myLogService.logSomething()) {
// We failed to log for some reason, abort!
formsSubmittingEventArgs.CancelAction = true;

}

Which solution is best in terms of sustainability to changes in future versions? I feeld like DataSubmissionService  is something you CAN create your own but maybe shouldn't?

#188857
Mar 06, 2018 7:46
Vote:
 
var formIdentity = new FormIdentity { Guid = formGuid, Language = formLanguage };

The formGuid is GUID of the FormContainerBlock.

Handling and cancel submitting event is more official way to archive. If it satisfy your requirement, just use it. otherwise try the override services.

#188859
Mar 06, 2018 8:37
Vote:
 

I will go with the more official way but for completeness, how do I retrieve the formGuid and formlanguage by only having

public override SubmitActionResult PerformDataSubmit(NameValueCollection rawSubmittedData, HttpContextBase httpContext,
            ControllerBase controller)

Thanks for your help.

#188860
Mar 06, 2018 8:46
Vote:
 

Here is how to retrieve form guid and language

var formLanguage = rawSubmittedData[Constants.FormLanguage];
var sFormGuid = rawSubmittedData[Constants.FormGuidKey] as string;
#188861
Mar 06, 2018 8:56
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.