示例#1
0
        public async Task <ResultModel <IList <MailListModel> > > GetList(FiltroModel filtroModel = null)
        {
            var action = "list";

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var url = String.Format("{0}/{1}/{2}?{3}&{4}", _baseUri.GetURI(), _modulo, action,
                                            _baseUri.GetAPIKEY(), _baseUri.GetFormat());
                    if (filtroModel != null)
                    {
                        url += String.Format("&{0}", filtroModel.GetSearchQuery("MailListsIds"));
                    }
                    HttpResponseMessage response =
                        await client.GetAsync(url);

                    response.EnsureSuccessStatusCode();

                    string json = await response.Content.ReadAsStringAsync();

                    JObject rss = JObject.Parse(json);

                    try
                    {
                        JArray items = (JArray)rss["root"]["ajaxResponse"]["list"]["item"];

                        IList <MailListModel> models = new List <MailListModel>();
                        if (items != null)
                        {
                            foreach (var item in items.Children())
                            {
                                models.Add(item.ToObject <MailListModel>());
                            }
                            return(new SuccessResultModel <IList <MailListModel> >(models));
                        }
                        else
                        {
                            return(new ErrorResultModel <IList <MailListModel> >(
                                       "No se encontraron Listas de mails que coincidan con la búsqueda realizada"));
                        }
                    }
                    catch
                    {
                        JToken item = rss["root"]["ajaxResponse"]["errors"];
                        return(new ErrorResultModel <IList <MailListModel> >(item.ToString()));
                    }
                }
            }
            catch (Exception e)
            {
                return(new ErrorResultModel <IList <MailListModel> >(e.Message));
            }
        }
示例#2
0
        public async Task <ResultModel <bool> > SaveContentInCampaign(ContentModel model, string campaignId = null)
        {
            var action = "edit";

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var parameters = new List <KeyValuePair <string, string> >();

                    if (!string.IsNullOrEmpty(campaignId.Trim()))
                    {
                        parameters.Add(new KeyValuePair <string, string>("CampaignID", campaignId));
                    }
                    else
                    {
                        parameters.Add(new KeyValuePair <string, string>("CampaignID", model.CampaignID.ToString()));
                    }

                    if (!string.IsNullOrEmpty(model.HTML))
                    {
                        parameters.Add(new KeyValuePair <string, string>("HTML", model.HTML));
                    }

                    if (!string.IsNullOrEmpty(model.PlainText))
                    {
                        parameters.Add(new KeyValuePair <string, string>("PlainText", model.PlainText));
                    }

                    if (!string.IsNullOrEmpty(model.RemoteUnsubscribeBlock))
                    {
                        parameters.Add(new KeyValuePair <string, string>("RemoteUnsubscribeBlock", model.RemoteUnsubscribeBlock));
                    }

                    var url = String.Format("{0}/{1}/{2}?{3}&{4}", _baseUri.GetURI(), _modulo, action,
                                            _baseUri.GetAPIKEY(), _baseUri.GetFormat());

                    var content = new MultipartFormDataContent();
                    foreach (var parameter in parameters)
                    {
                        content.Add(new StringContent(parameter.Value), parameter.Key);
                    }

                    var response = await client.PostAsync(url, content);

                    response.EnsureSuccessStatusCode();

                    string json = await response.Content.ReadAsStringAsync();

                    JObject rss = JObject.Parse(json);

                    try
                    {
                        JToken item = rss["root"]["ajaxResponse"]["success"];

                        var responseObject = item.ToObject <int>();

                        var contentCreated = responseObject > 0;
                        return(new SuccessResultModel <bool>(contentCreated));
                    }
                    catch
                    {
                        JToken item = rss["root"]["ajaxResponse"]["errors"];
                        return(new ErrorResultModel <bool>(item.ToString()));
                    }
                }
            }
            catch (Exception e)
            {
                return(new ErrorResultModel <bool>(e.Message));
            }
        }