Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CustomSubmitAction : SubmitActionBase<string>
- {
- private FormSubmitContext _formSubmitContext;
- public CustomSubmitAction(ISubmitActionData submitActionData) : base(submitActionData)
- {
- }
- protected override bool Execute(string data, FormSubmitContext formSubmitContext)
- {
- try
- {
- this._formSubmitContext = formSubmitContext;
- var nameFieldValue = GetValue(this._formSubmitContext.Fields.FirstOrDefault(f => f.Name.Equals("txtName")));
- var emailFieldValue = GetValue(this._formSubmitContext.Fields.FirstOrDefault(f => f.Name.Equals("txtMail")));
- using (MailMessage mail = new MailMessage())
- {
- //email functinality
- //smtp.Send(mail); scenario1 -->if email send successfully, i have to show custom message like "Message is send successfully"
- }
- return true;
- }
- catch (Exception e)
- {
- Log.Error($" mail failed ", e, this);
- formSubmitContext.Abort(); //scenario-2-- >if email failed, i have to show custom message like "Message is not send successfully"
- }
- return false;
- }
- protected override bool TryParse(string value, out string target)
- {
- target = string.Empty;
- return true;
- }
- private static string GetValue(object field)
- {
- return field?.GetType().GetProperty("Value")?.GetValue(field, null)?.ToString() ?? string.Empty;
- }
- }
Add Comment
Please, Sign In to add comment