Guest User

Untitled

a guest
Jan 24th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public class CustomSubmitAction : SubmitActionBase<string>
  2. {
  3. private FormSubmitContext _formSubmitContext;
  4. public CustomSubmitAction(ISubmitActionData submitActionData) : base(submitActionData)
  5. {
  6. }
  7. protected override bool Execute(string data, FormSubmitContext formSubmitContext)
  8. {
  9.  
  10. try
  11. {
  12. this._formSubmitContext = formSubmitContext;
  13. var nameFieldValue = GetValue(this._formSubmitContext.Fields.FirstOrDefault(f => f.Name.Equals("txtName")));
  14. var emailFieldValue = GetValue(this._formSubmitContext.Fields.FirstOrDefault(f => f.Name.Equals("txtMail")));
  15.  
  16. using (MailMessage mail = new MailMessage())
  17. {
  18. //email functinality
  19. //smtp.Send(mail); scenario1 -->if email send successfully, i have to show custom message like "Message is send successfully"
  20. }
  21. return true;
  22. }
  23. catch (Exception e)
  24. {
  25. Log.Error($" mail failed ", e, this);
  26. formSubmitContext.Abort(); //scenario-2-- >if email failed, i have to show custom message like "Message is not send successfully"
  27. }
  28. return false;
  29. }
  30. protected override bool TryParse(string value, out string target)
  31. {
  32. target = string.Empty;
  33. return true;
  34. }
  35. private static string GetValue(object field)
  36. {
  37. return field?.GetType().GetProperty("Value")?.GetValue(field, null)?.ToString() ?? string.Empty;
  38. }
  39. }
Add Comment
Please, Sign In to add comment