private void update(int id) { try { //Fill Template Mailee.Template template = new Mailee.Template(); template.Id = id; template.Title = txtTitle.Text; template.Html = txtHtml.Text; //Save Template template.save(); //Redirect Response.Redirect("View.aspx"); } catch (Mailee.RestExcepction ex) { //Show http status Response.Write(string.Format("statusCode = {0} <br /> statusDescription = {1}", ex.StatusCode, ex.StatusDesciption)); //Show error messages foreach (string error in ex.ErrorMessages) Response.Write("<br />" + error); } catch (Exception ex) { Response.Write(ex.Message); } }
/// <summary> /// Find Template by ID /// </summary> /// <param name="id">Template ID</param> public static Mailee.Template findById(int id) { Mailee.Template template = new Mailee.Template(); //Validation if (id == 0) return template; //URL (GET) (api.XXXXXXXXXXXXX.subdomain.mailee.me/templates/X.xml) string url = string.Format("{0}templates/{1}.xml", Mailee.Config.UrlAPI, id); //Get data string htmlReponse = Mailee.Rest.get(url); //Checks if the xml is valid bool isValidXml = Mailee.Util.IsValidXML(htmlReponse); if (isValidXml == true) { //Create XML XmlDocument xmlDoc = new XmlDocument(); //Load XML xmlDoc.LoadXml(htmlReponse); //Get Template XmlNodeList xmlTemplates = xmlDoc.GetElementsByTagName("template"); if (xmlTemplates.Count > 0) { XmlNode xmlTemplate = xmlTemplates[0]; //Set properties template.ClientId = Mailee.Util.parseInt(xmlTemplate.ChildNodes[0].InnerText); template.CreatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[1].InnerText); template.DeletedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[2].InnerText); template.Html = xmlTemplate.ChildNodes[3].InnerText; template.Id = Mailee.Util.parseInt(xmlTemplate.ChildNodes[4].InnerText); template.Simulations = xmlTemplate.ChildNodes[5].InnerText; template.ThumbContentType = xmlTemplate.ChildNodes[6].InnerText; template.ThumbFileName = xmlTemplate.ChildNodes[7].InnerText; template.ThumbFileSize = Mailee.Util.parseInt(xmlTemplate.ChildNodes[8].InnerText); template.ThumbUpdatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[9].InnerText); template.Title = xmlTemplate.ChildNodes[10].InnerText; template.UpdatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[11].InnerText); } } return template; }
/// <summary> /// Find all Templates /// </summary> public static List<Mailee.Template> findAll() { List<Mailee.Template> templates = new List<Mailee.Template>(); //URL (GET) (api.XXXXXXXXXXXXX.subdomain.mailee.me/templates) string url = string.Concat(Mailee.Config.UrlAPI, "templates.xml"); //Get data string htmlReponse = Mailee.Rest.get(url); //Create XML XmlDocument xmlDoc = new XmlDocument(); //Load XML xmlDoc.LoadXml(htmlReponse); //Get Templates XmlNodeList xmlTemplates = xmlDoc.GetElementsByTagName("template"); //Each Tenplates foreach (XmlNode xmlTemplate in xmlTemplates) { //Create new Template Mailee.Template newTemplate = new Mailee.Template(); //Set properties newTemplate.ClientId = Mailee.Util.parseInt(xmlTemplate.ChildNodes[0].InnerText); newTemplate.CreatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[1].InnerText); newTemplate.DeletedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[2].InnerText); newTemplate.Html = xmlTemplate.ChildNodes[3].InnerText; newTemplate.Id = Mailee.Util.parseInt(xmlTemplate.ChildNodes[4].InnerText); newTemplate.Simulations = xmlTemplate.ChildNodes[5].InnerText; newTemplate.ThumbContentType = xmlTemplate.ChildNodes[6].InnerText; newTemplate.ThumbFileName = xmlTemplate.ChildNodes[7].InnerText; newTemplate.ThumbFileSize = Mailee.Util.parseInt(xmlTemplate.ChildNodes[8].InnerText); newTemplate.ThumbUpdatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[9].InnerText); newTemplate.Title = xmlTemplate.ChildNodes[10].InnerText; newTemplate.UpdatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[11].InnerText); //Add Template templates.Add(newTemplate); } return templates; }