private void PropertiesRefreshReminder()
{
try
{
var now = DateTime.Now;
var dlo = new DataLoadOptions();
dlo.LoadWith<Agency>(c => c.User);
dlo.LoadWith<Affiliation>(c => c.Agencies);
dlo.LoadWith<AgencyOffice>(c => c.Agency);
dlo.LoadWith<AgencyOffice>(c => c.Agents);
dlo.LoadWith<Agent>(c => c.AgentContactFrequency);
dlo.LoadWith<Agent>(c => c.User);
dlo.LoadWith<Property>(c => c.AlertContents);
dlo.LoadWith<Property>(c => c.Frequency);
dlo.LoadWith<Property>(c => c.PropMarket);
dlo.LoadWith<Property>(c => c.PropertyType);
dlo.LoadWith<Property>(c => c.PropertyHits);
dlo.LoadWith<Property>(c => c.District);
dlo.LoadWith<Property>(c => c.CountyCity);
dlo.LoadWith<Property>(c => c.Country);
using (var dc = new findahomeDataContext() { CommandTimeout = 600, LoadOptions = dlo })
{
// Get List of Property That online and has been 3 months not modify
var expiredPropertyList = dc.Properties.Where(c => c.ModifyDate < DateTime.Now.AddMonths(-3) && c.idCRule.Equals(1) && c.User.AgencyOffices.Agency.Affiliation.idAffiliation.Equals(3)).Take(5).ToList();
foreach(var EP in expiredPropertyList)
{
var template = dc.InOut_Target_Contents.Where(c => c.Website_Id == Settings.Default.fourpmWebsiteId).ToList();
var body = new StringBuilder();
//Build Property Info Lines
var EmailLines = String.Format(template.First(c => c.Name.Equals(Settings.Default.PropertyReminderLines)).Text, EP.idList, EP.DisplayAddress, EP.idList, EP.Description.Length > 200 ? EP.Description.Substring(0, 200) : EP.Description);
//Build Email Body
body.AppendFormat(template.First(c => c.Name.Equals(Settings.Default.EmailReport_template_reminder_onview)).Text, EP.User.Name, EmailLines, EP.idList, String.Format(EP.User.idUser + "." + EP.User.Key));
//Send Email Part
var report = new MailMessage(Settings.Default.ReportEmail, "kidd@4pm.ie",
string.Format(Settings.Default.PropertyReminderSubject), body.ToString()) { IsBodyHtml = true };
//report.Bcc.Add(Settings.Default.ReportEmail);
report.ReplyTo = new MailAddress(template.First(c => c.Name.Equals(Settings.Default.propertyreport_replyto)).Text);
smtpClient.Send(report);
// Take Offline the Property
/*
EP.idCRule = 3;
EP.ModifyDate = DateTime.Now;
dc.SubmitChanges();
* */
}
}
}
catch (Exception ex)
{
Trace.TraceError(ex.ToString());
}
}