appendices)
{
var template =
"" +
" " +
" Übersicht \"Nicht verhandelte Nachträge\"
" +
" Folgende Nachträge haben ein Einreichdatum älter als 8 Wochen, jedoch noch kein Verhandlungstermin" +
" gesetzt:
" +
" " +
" " +
"";
if (!appendices.Any()) return String.Format(template, String.Empty);
var appendicesList = String.Empty;
foreach (var appendix in appendices)
{
appendicesList += String.Format(
"Baustelle \"{0}\" - Nachtrag \"{1}\" - Einreichdatum: {2:dd.MM.yyyy}",
appendix.Site == null
? String.Empty
: appendix.Site.CustomNumber,
appendix.CustomNumber,
appendix.OfferingDate);
}
return String.Format(template, appendicesList);
}
///
/// Generates a mail body with a list of all appendices with a negotiation date later than N weeks and not existing protocol
///
/// Appendices matching that criteria.
public string GenerateNegotiationProtocolMailBody(IEnumerable appendices)
{
var template =
"" +
" " +
" Übersicht \"Verhandelte Nachträge ohne Protokoll\"
" +
" Folgende Nachträge haben ein Verhandlungstermin älter als zwei Wochen, jedoch noch kein Protokoll:" +
"
" +
" " +
"";
if (!appendices.Any()) return String.Format(template, String.Empty);
var appendicesList = String.Empty;
foreach (var appendix in appendices)
{
appendicesList += String.Format(
"Baustelle \"{0}\" - Nachtrag \"{1}\" - Verhandlungsdatum: {2:dd.MM.yyyy}",
appendix.Site == null
? String.Empty
: appendix.Site.CustomNumber,
appendix.CustomNumber,
appendix.NegotiationDate);
}
return String.Format(template, appendicesList);
}
///
/// Generates a mail body with a list of all appendices with a negotiation date later than N weeks and not existing order number
///
/// Appendices matching that criteria.
public string GenerateNegotiationOrderMailBody(IEnumerable appendices)
{
var template =
"" +
" " +
" Übersicht \"Verhandelte Nachträge ohne Bestellnummer\"
" +
" Folgende Nachträge haben ein Verhandlungstermin älter als zwei Wochen, jedoch noch keine Bestellnummer:" +
"
" +
" " +
"";
if (!appendices.Any()) return String.Format(template, String.Empty);
var appendicesList = String.Empty;
foreach (var appendix in appendices)
{
appendicesList += String.Format(
" Baustelle \"{1}\" - Nachtrag \"{0}\" - Verhandlungsdatum: {2:dd.MM.yyyy}",
appendix.Site == null
? String.Empty
: appendix.Site.CustomNumber,
appendix.CustomNumber,
appendix.NegotiationDate);
}
return String.Format(template, appendicesList);
}
#endregion
#region Mail sending
///
/// Sends a generated mail body to the specified recipients in the mail notification
///
/// The mail notification.
/// The mail subject.
/// The mail body.
public void SendNotification(MailNotification mailNotification, string subject, string body)
{
if (mailNotification == null) return;
var mailServerConfig = _configurationService.GetCurrentConfiguration().MailServerElement;
var smptClient = new SmtpClient(mailServerConfig.SmtpServer, mailServerConfig.Port)
{
EnableSsl = mailServerConfig.UseSsl,
Credentials = new NetworkCredential(
mailServerConfig.Username,
mailServerConfig.Password,
mailServerConfig.Domain)
};
var recipients =
mailNotification.Users
.Select(u => u.MailAddress);
var mailMessage = new MailMessage
{
IsBodyHtml = true,
Subject = subject,
Body = body,
From = new MailAddress("Nachtragsbenachrichtigung@schweerbau.de")
};
foreach (var recipient in recipients)
mailMessage.To.Add(recipient);
smptClient.Send(mailMessage);
}
#endregion
#region Helper
///
/// Determines the calendar week of a specific datetime
///
/// The datetime which calendarweek should be calculated.
public static int GetCalendarWeek(DateTime date)
{
var currentCulture = CultureInfo.CurrentCulture;
var calendar = currentCulture.Calendar;
var calendarWeek = calendar.GetWeekOfYear(
date,
currentCulture.DateTimeFormat.CalendarWeekRule,
currentCulture.DateTimeFormat.FirstDayOfWeek);
if (calendarWeek > 52)
{
date = date.AddDays(7);
var testCalendarWeek = calendar.GetWeekOfYear(date,
currentCulture.DateTimeFormat.CalendarWeekRule,
currentCulture.DateTimeFormat.FirstDayOfWeek);
if (testCalendarWeek == 2)
calendarWeek = 1;
}
return calendarWeek;
}
#endregion
}
}