Guest User

Untitled

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