public async Task<ResultModel<CampaignCreatedModel>> CreateAndEdit(CreateCampaignModel campaignModel) { var action = "edit"; try { using (HttpClient client = new HttpClient()) { var parameters = new List<KeyValuePair<string, string>>(); if (campaignModel.CampaignID.HasValue) { parameters.Add(new KeyValuePair<string, string>("CampaignID", campaignModel.CampaignID.Value.ToString())); } if (!string.IsNullOrEmpty(campaignModel.CampaignName)) { parameters.Add(new KeyValuePair<string, string>("CampaignName", campaignModel.CampaignName)); } if (!string.IsNullOrEmpty(campaignModel.CampaignSubject)) { parameters.Add(new KeyValuePair<string, string>("CampaignSubject", campaignModel.CampaignSubject)); } foreach (var mailList in campaignModel.MailListsIds) { parameters.Add(new KeyValuePair<string, string>("MailListsIds[]", mailList.ToString())); } if (campaignModel.FromId.HasValue) { parameters.Add(new KeyValuePair<string, string>("FromID", campaignModel.FromId.Value.ToString())); } if (campaignModel.ReplyToId.HasValue) { parameters.Add(new KeyValuePair<string, string>("ReplyToID", campaignModel.ReplyToId.Value.ToString())); } parameters.Add(new KeyValuePair<string, string>("TrackLinkClicks", Convert.ToInt32(campaignModel.TrackLinkClicks).ToString())); parameters.Add(new KeyValuePair<string, string>("TrackReads", Convert.ToInt32(campaignModel.TrackReads).ToString())); parameters.Add(new KeyValuePair<string, string>("TrackAnalitics", Convert.ToInt32(campaignModel.TrackAnalitics).ToString())); parameters.Add(new KeyValuePair<string, string>("SendStateReport", Convert.ToInt32(campaignModel.SendStateReport).ToString())); parameters.Add(new KeyValuePair<string, string>("ScheduleCampaign", Convert.ToInt32(campaignModel.ScheduleCampaign).ToString())); if (campaignModel.SendDate.HasValue) { parameters.Add(new KeyValuePair<string, string>("SendDate", campaignModel.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss"))); } if (!campaignModel.DontSendNow) { parameters.Add(new KeyValuePair<string, string>("SendNow", "1")); } var formContent = new FormUrlEncodedContent(parameters); var url = String.Format("{0}/{1}/{2}?{3}&{4}", _baseUri.GetURI(), _modulo, action, _baseUri.GetAPIKEY(), _baseUri.GetFormat()); HttpResponseMessage response = await client.PostAsync(url, formContent); response.EnsureSuccessStatusCode(); string json = await response.Content.ReadAsStringAsync(); JObject rss = JObject.Parse(json); try { JToken item = rss["root"]["ajaxResponse"]["campaign"]; CampaignCreatedModel campaingCreatedModel = new CampaignCreatedModel(); campaingCreatedModel = item.ToObject<CampaignCreatedModel>(); return new SuccessResultModel<CampaignCreatedModel>(campaingCreatedModel); } catch { JToken item = rss["root"]["ajaxResponse"]["errors"]; return new ErrorResultModel<CampaignCreatedModel>(item.ToString()); } } } catch (Exception e) { return new ErrorResultModel<CampaignCreatedModel>(e.Message); } }
public CampaignWithContentResponseModel() { Campaign = new CampaignCreatedModel(); ContentCampaign = new ContentModel(); ContentSaved = false; }