/// <summary> /// Creaing a content including the form questions and provided feedback by the resource. /// </summary> /// <param name="surveyDto"></param> /// <returns>Mail Content</returns> public string GenerateSurveyMailBody(SurveyFormDto surveyDto) { // Static Option Array of survey form. string[] optionArray = { "totalmente in disaccordo", "abbastanza in disaccordo", "abbastanza d’accordo", "totalmente d’accordo" }; var mailContent = ""; for (int i = 0; i < (surveyDto.Feedback.Length); i++) { mailContent += // Concatenating the question in the mail body. "Q: " + surveyDto.Questions[i] // Feedback 'TEXT' is being retreived from the Option Array and concatenating to the mail body. + " : <b>" + optionArray[Int32.Parse(surveyDto.Feedback[i])] + "</b><br />"; } // Concatenating some additional text to the mail body. string mailBody = "<br />Dear User" + ",<br /><br /> <br/>" + "Here is your provided feedback : <br /> " + mailContent; return(mailBody); }
public IActionResult FormSubmit([FromBody] SurveyFormDto surveyFromDto) { try { if (surveyFromDto == null) { return(NotFound()); } // Retrieving the mail body along with the questions and provided feedback. var mailBody = _surveyManager.GenerateSurveyMailBody(surveyFromDto); List <string> emailList = surveyFromDto.Email.Split(';').ToList <string>(); emailList.Reverse(); // Sending Invitation to the specific resource mail foreach (var email in emailList) { // Initiating the mail address _emailManager.To.Add(email); } // Sending mail to that specific person's mail by whom the survey feedback is provided. _emailManager.Subject = "Talent_Survey_Form"; _emailManager.Body = mailBody.ToString(); _emailManager.Send(); // Storing data regarding Survey feedback. //Database tables aren't ready yet! return(Ok()); } catch (Exception x) { var result = new { error = x.StackTrace, error_type = x.InnerException, message = x.Message }; // Returning Exception object. return(BadRequest(result)); } }