protected void Page_Load(object sender, EventArgs e)
{
phoneNoList.DataSource = Utility.Controller.GetUniquePhoneNo(fromPhoneNo);
phoneNoList.DataBind();
}
protected void sendMsg_Click(object sender, EventArgs e)
{
#region add a record to all message xml
Domain.User u = new Domain.User();
u.fullName = fullName.Text;
u.from = "+1" + fromPhoneNo;
u.to = "+1" + toPhoneNo.Text;
u.body = body.Text;
u.dateTimeSent = DateTime.Now.ToString();
u.direction = "outbound-reply";
string result = Utility.XML.Add(Utility.Controller.filePathUserMessagesAll, u);
#endregion
}
public static string Add(string inputFilePath,Domain.User u)
{
XDocument doc = XDocument.Load(inputFilePath);
XElement user = new XElement("User",
new XAttribute("PhoneNo",""),
new XElement("FullName",u.fullName),
new XElement("From",u.from),
new XElement("To",u.to),
new XElement("Body",u.body),
new XElement("DateTimeSent",u.dateTimeSent),
new XElement("Direction",u.direction),
new XElement("Carrier",
new XElement("Name","Twilio"),
new XElement("SID",Utility.Controller.TwilioSID),
new XElement("Token",Utility.Controller.TwilioToken)));
doc.Root.Add(user);
doc.Save(inputFilePath);
return "Added";
}
public static DataTable GetUniquePhoneNo(string accountPhoneNo)
{
string clientPhoneNo = string.Empty;
string inputFilePath = filePathUserMessagesAll;
//@"C:\Users\Documents\visual studio 2015\Projects\AppText\AppText\Data\UserMessagesAll.xml";
DataTable dt = new DataTable();
dt.Clear();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("PhoneNo",typeof(string)),
new DataColumn("Client",typeof(string)),
new DataColumn("DateCreated",typeof(string))
});
XDocument xdoc = null;
using (XmlReader xr = XmlReader.Create(inputFilePath))
{
xdoc = XDocument.Load(xr);
var query1 = from t in xdoc.Descendants("User")
where t.Element("From").Value.ToLower() == "+1" + accountPhoneNo.ToLower()
select new
{
To = t.Element("To").Value,
FullName = t.Element("FullName").Value,
DateTimeSent = t.Element("DateTimeSent").Value
//DateTime.Parse(txtDatepicker_end.Text).ToString("YYYY-MM-dd");
};
var query2 = from t in xdoc.Descendants("User")
where t.Element("To").Value.ToLower() == "+1" + accountPhoneNo.ToLower()
select new
{
To = t.Element("From").Value,
FullName = t.Element("FullName").Value,
DateTimeSent = t.Element("DateTimeSent").Value
};
var query3 = query1.Concat(query2).OrderByDescending(z => z.DateTimeSent).GroupBy( z => z.To).Select(z=> z.First());
foreach (var x in query3)
{
dt.Rows.Add(x.To, x.FullName, (DateTime.Parse(x.DateTimeSent)).ToString("MM/dd/yy", System.Globalization.CultureInfo.InvariantCulture));
}
// string timeF = "2017-06-15T14:49:19-07:00";
// DateTime dt = DateTime.Parse(timeF);
// string timeS = dt.ToUniversalTime().ToString("MM/dd/yy hh:mm", System.Globalization.CultureInfo.InvariantCulture);
// var messages2a = MessageResource.Read().Where(x => x.From.ToString() == "+1" + fromPhoneNo).GroupBy(x => x.To).Select(y => y.First());
// var messages3a = MessageResource.Read().Where(y => y.To == "+1" + fromPhoneNo).GroupBy(x => x.To).Select(y => y.First());
// var allz = messages2a.Concat(messages3a).OrderByDescending(z => z.DateCreated);
return dt;
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE