public bool SendDailySurveysEmail(RouterUser user, List <RouterReturn> surveys, out string message) { MessageEventBody body = CreateMessageBody(user, surveys); Uri uri = new Uri("https://api.listrak.com/email/v1/List/248553/Contact?eventIds=12598"); var response = _client.PostAsJsonAsync(uri, body).Result; var result = response.Content.ReadAsStringAsync().Result; message = result; MailSendReturnStatus status = JsonConvert.DeserializeObject <MailSendReturnStatus>(result); if (status.status == 200 || status.status == 201) { return(true); } return(false); }
private MessageEventBody CreateMessageBody(RouterUser user, List <RouterReturn> surveys) { RouterReturn survey1 = surveys.First(); RouterReturn survey2 = surveys.Skip(1).Take(1).First(); RouterReturn survey3 = surveys.Skip(2).Take(1).First(); var survey1Reward = survey1.SubTitle.Split('*').ToList().Last(); MessageEventBody body = new MessageEventBody(); body.emailAddress = user.Email; body.subscriptionState = "Subscribed"; body.segmentationFieldValues = new Segmentationfieldvalue[] { new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.firstname, value = user.First }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveyreward1, value = survey1Reward }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveylink1, value = survey1.ProxyUrl }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveyname1, value = survey1.Title }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveystats1, value = survey1.SubTitle }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveylink2, value = survey2.ProxyUrl }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveyname2, value = survey2.Title }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveystats2, value = survey2.SubTitle }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveylink3, value = survey3.ProxyUrl }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveyname3, value = survey3.Title }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveystats3, value = survey3.SubTitle }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.dailysurveyslink, value = $"{ConfigurationManager.AppSettings["DailySurveysLink"]}{user.UniqueId}" }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.surveyquantity, value = (surveys.Count - 1).ToString() }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.date, value = DateTime.Today.ToLongDateString() }, new Segmentationfieldvalue() { segmentationFieldId = (int)DaileySurveyFields.time, value = $"{DateTime.Now:hh:mm tt}" } }; return(body); }