/// <summary> /// Sendet eine Notification an alle Schuldner einer Rechnung mit dem Link zur Bestätigung /// </summary> /// <param name="bill"></param> /// <param name="billUrl"></param> public void SendBillReceivedNotification(Bill bill, string billUrl) { Require.NotNull(bill, "bill"); foreach (BillUserGroupDebitor billUserGroupDebitor in FindDebitorsToNotifyOnBillCreated(bill)) { string userEmail = billUserGroupDebitor.UserGroupMembership.User.Email; ModelMap modelMap = new ModelMap(); modelMap.Add("debitor", billUserGroupDebitor.UserGroupMembership.User); modelMap.Add("creditor", bill.Creditor.User); modelMap.Add("billUrl", billUrl); modelMap.Add("bill", bill); modelMap.Add("amount", bill.GetPartialAmountByPortion(billUserGroupDebitor.Portion)); MailMessage mailMessage = EmailService.CreateMailMessage(userEmail, modelMap, "BillReceived"); EmailService.SendMessage(mailMessage); } foreach (var billGuestDebitor in bill.GuestDebitors) { string userEmail = billGuestDebitor.Email; ModelMap modelMap = new ModelMap(); modelMap.Add("debitor", billGuestDebitor); modelMap.Add("creditor", bill.Creditor.User); modelMap.Add("billUrl", billUrl); modelMap.Add("bill", bill); modelMap.Add("amount", bill.GetPartialAmountByPortion(billGuestDebitor.Portion)); MailMessage mailMessage = EmailService.CreateMailMessage(userEmail, modelMap, "BillReceivedGuest"); EmailService.SendMessage(mailMessage); } }
public void SendPeanutUpdateStateNotification(Peanut peanut, PeanutUpdateNotificationOptions notificationOptions, User user) { Require.NotNull(peanut, "peanut"); Require.NotNull(notificationOptions, "notificationOptions"); if (peanut.PeanutState == PeanutState.Started) { /*Der Peanut wurde gestartet => alle Teilnehmer, außer den ändernden Nutzer benachrichtigen*/ foreach (PeanutParticipation peanutParticipation in FindParticipatorsToNotifyOnUpdate(peanut, user)) { ModelMap modelMap = new ModelMap(); modelMap.Add("peanut", peanut); modelMap.Add("editor", user); modelMap.Add("recipient", peanutParticipation.UserGroupMembership.User); modelMap.Add("participation", peanutParticipation); modelMap.Add("peanutUrl", notificationOptions.PeanutUrl); MailMessage mailMessage = EmailService.CreateMailMessage(peanutParticipation.UserGroupMembership.User.Email, modelMap, "PeanutStart"); EmailService.SendMessage(mailMessage); } } if (peanut.PeanutState == PeanutState.PurchasingDone) { /*Der Beschaffung der Voraussetzungen für den Peanut ist abgeschlossen => alle Produzenten, außer den ändernden Nutzer, benachrichtigen*/ foreach (PeanutParticipation peanutParticipation in FindProducersToNotifyOnPurchasingDone(peanut, user)) { ModelMap modelMap = new ModelMap(); modelMap.Add("peanut", peanut); modelMap.Add("editor", user); modelMap.Add("recipient", peanutParticipation.UserGroupMembership.User); modelMap.Add("participation", peanutParticipation); modelMap.Add("peanutUrl", notificationOptions.PeanutUrl); MailMessage mailMessage = EmailService.CreateMailMessage(peanutParticipation.UserGroupMembership.User.Email, modelMap, "PeanutPurchasingDone"); EmailService.SendMessage(mailMessage); } } if (peanut.PeanutState == PeanutState.Canceled) { /*Der Peanut wurde abgesagt => alle Teilnehmer, außer den ändernden Nutzer benachrichtigen*/ foreach (PeanutParticipation peanutParticipation in FindParticipatorsToNotifyOnUpdate(peanut, user)) { ModelMap modelMap = new ModelMap(); modelMap.Add("peanut", peanut); modelMap.Add("editor", user); modelMap.Add("recipient", peanutParticipation.UserGroupMembership.User); modelMap.Add("participation", peanutParticipation); modelMap.Add("peanutUrl", notificationOptions.PeanutUrl); MailMessage mailMessage = EmailService.CreateMailMessage(peanutParticipation.UserGroupMembership.User.Email, modelMap, "PeanutCanceled"); EmailService.SendMessage(mailMessage); } } }
/// <summary> /// Erstellt ein EmailModel für das PasswordReset und gibt dieses zurück /// </summary> /// <param name="user"></param> /// <param name="baseLink"></param> /// <returns></returns> private ModelMap GetEmailModelForPasswordReset(User user, string baseLink) { ModelMap emailModel = new ModelMap(); emailModel.Add("user", user); emailModel.Add("baseLink", baseLink); return(emailModel); }
private ModelMap GetEmailModelForEmailConfirmation(string name, string confirmationLink) { ModelMap emailModel = new ModelMap(); emailModel.Add("name", name); emailModel.Add("confirmationLink", confirmationLink); return(emailModel); }
/// <summary> /// Sendet eine Notification an den Nutzer das er zu einer Mitgliedschaft in einer Gruppe eingeladen wurde /// </summary> /// <param name="user"></param> /// <param name="allMembershipsUrl"></param> public void SendUserGroupInvitationNotification(User user, string allMembershipsUrl) { Require.NotNull(user, "user"); ModelMap modelMap = new ModelMap(); modelMap.Add("user", user); modelMap.Add("groupLink", allMembershipsUrl); MailMessage mailMessage = EmailService.CreateMailMessage(user.Email, modelMap, "InviteMembership"); EmailService.SendMessage(mailMessage); }
/// <summary> /// Sendet eine Notification an den Nutzer mit der Information das sich ein Nutzer um eine Mitgliedschaft in einer /// Gruppe beworben hat. /// </summary> /// <param name="user"></param> /// <param name="urlToUserGroup"></param> public void SendRequestMembershipNotification(User user, string urlToUserGroup) { Require.NotNull(user, "user"); ModelMap modelMap = new ModelMap(); modelMap.Add("user", user); modelMap.Add("groupLink", urlToUserGroup); MailMessage mailMessage = EmailService.CreateMailMessage(user.Email, modelMap, "RequestMembership"); EmailService.SendMessage(mailMessage); }
public void SendNotificationAboutUserActivation(User user, string editLink) { Require.NotNull(user, "user"); ModelMap emailModel = new ModelMap(); emailModel.Add("user", user); emailModel.Add("editLink", editLink); foreach (User admin in UserService.FindAllAdmins()) { MailMessage mailMessage = EmailService.CreateMailMessage(admin.Email, emailModel, "NotificationAboutUserActivation"); EmailService.SendMessage(mailMessage); } }
public void SendPeanutCommentNotification(Peanut peanut, string comment, PeanutUpdateNotificationOptions notificationOptions, User user) { Require.NotNull(peanut, "peanut"); foreach (PeanutParticipation peanutParticipation in FindParticipatorsToNotifyOnUpdate(peanut, user)) { ModelMap modelMap = new ModelMap(); modelMap.Add("peanut", peanut); modelMap.Add("user", user); modelMap.Add("recipient", peanutParticipation.UserGroupMembership.User); modelMap.Add("peanutUrl", notificationOptions.PeanutUrl); modelMap.Add("comment", comment); MailMessage mailMessage = EmailService.CreateMailMessage(peanutParticipation.UserGroupMembership.User.Email, modelMap, "PeanutComment"); EmailService.SendMessage(mailMessage); } }
/// <summary> /// Sendet eine Notification an denjenigen der eine Zahlung erhalten hat. /// </summary> /// <param name="payment"></param> /// <param name="paymentUrl"></param> public void SendPaymentReceivedNotification(Payment payment, string paymentUrl) { Require.NotNull(payment, "payment"); string userEmail = payment.Recipient.Membership.User.Email; ModelMap modelMap = new ModelMap(); modelMap.Add("recipient", payment.Recipient.Membership.User); modelMap.Add("sender", payment.Sender.Membership.User); modelMap.Add("paymentUrl", paymentUrl); modelMap.Add("payment", payment); modelMap.Add("amount", payment.Amount); MailMessage mailMessage = EmailService.CreateMailMessage(userEmail, modelMap, "PaymentReceived"); EmailService.SendMessage(mailMessage); }
public void SendBillAcceptedNotification(Bill bill, string billUrl, string settleBillUrl) { Require.NotNull(bill, "bill"); if (bill.Creditor.User.NotifyMeAsCreditorOnSettleableBills) { string userEmail = bill.Creditor.User.Email; ModelMap modelMap = new ModelMap(); modelMap.Add("creditor", bill.Creditor.User); modelMap.Add("bill", bill); modelMap.Add("billUrl", billUrl); modelMap.Add("settleBillUrl", settleBillUrl); MailMessage mailMessage = EmailService.CreateMailMessage(userEmail, modelMap, "BillAccepted"); EmailService.SendMessage(mailMessage); } }
public void SendBillDeclinedNotification(Bill bill, BillUserGroupDebitor decliningDebitor, string billUrl) { Require.NotNull(bill, "bill"); Require.NotNull(decliningDebitor, "decliningDebitor"); if (bill.Creditor.User.NotifyMeAsCreditorOnDeclinedBills) { string userEmail = bill.Creditor.User.Email; ModelMap modelMap = new ModelMap(); modelMap.Add("creditor", bill.Creditor.User); modelMap.Add("debitor", decliningDebitor.UserGroupMembership.User); modelMap.Add("userGroupDebitor", decliningDebitor); modelMap.Add("bill", bill); modelMap.Add("billUrl", billUrl); MailMessage mailMessage = EmailService.CreateMailMessage(userEmail, modelMap, "BillDeclined"); EmailService.SendMessage(mailMessage); } }
public void SendPeanutInvitationNotification(Peanut peanut, User notifiedUser, PeanutInvitationNotificationOptions notificationOptions, User user) { Require.NotNull(notificationOptions, "notificationOptions"); Require.NotNull(user, "user"); if (notifiedUser.NotifyMeOnPeanutInvitation) { ModelMap modelMap = new ModelMap(); modelMap.Add("peanut", peanut); modelMap.Add("user", user); modelMap.Add("recipient", notifiedUser); modelMap.Add("peanutUrl", notificationOptions.PeanutUrl); modelMap.Add("attendPeanutUrl", notificationOptions.AttendPeanutUrl); MailMessage mailMessage = EmailService.CreateMailMessage(notifiedUser.Email, modelMap, "PeanutInvitation"); EmailService.SendMessage(mailMessage); } }
public void SendPeanutUpdateRequirementsNotification(Peanut peanut, string updateComment, PeanutUpdateRequirementsNotificationOptions notificationOptions, User user) { Require.NotNull(peanut, "peanut"); Require.NotNull(notificationOptions, "notificationOptions"); Require.NotNull(user, "user"); if (string.IsNullOrWhiteSpace(updateComment)) { updateComment = "-"; } foreach (PeanutParticipation creditors in FindCreditorsToNotifyOnRequirementsChange(peanut, user)) { ModelMap modelMap = new ModelMap(); modelMap.Add("peanut", peanut); modelMap.Add("editor", user); modelMap.Add("recipient", creditors.UserGroupMembership.User); modelMap.Add("peanutUrl", notificationOptions.PeanutUrl); modelMap.Add("requirements", string.Join(Environment.NewLine, peanut.Requirements.Select(r => string.Format("<li>{0} {1}</li>", r.QuantityAndUnit, r.Name)))); modelMap.Add("updateComment", updateComment); MailMessage mailMessage = EmailService.CreateMailMessage(creditors.UserGroupMembership.User.Email, modelMap, "PeanutRequirementsUpdated"); EmailService.SendMessage(mailMessage); } }
public void TestMultiplePlaceholdersOfDifferentDepth() { /* Given: Ein Template mit einem 3-teiligen Platzhalter-Pfad */ const string TEMPLATE = "Mein Name ist {user.name.firstname} {user.name.lastname}. Ich habe im Jahr {application.year} eine tolle Software namens {application.name} entwickelt."; const string FIRST_NAME_VALUE = "Tobias"; const string LAST_NAME_VALUE = "Jäkel"; const string APPLICATION_YEAR_VALUE = "2000"; const string APPLICATION_NAME_VALUE = "Bubble Sort"; string expectedString = TEMPLATE; expectedString = expectedString.Replace("{user.name.firstname}", FIRST_NAME_VALUE); expectedString = expectedString.Replace("{user.name.lastname}", LAST_NAME_VALUE); expectedString = expectedString.Replace("{application.year}", APPLICATION_YEAR_VALUE); expectedString = expectedString.Replace("{application.name}", APPLICATION_NAME_VALUE); /* When: Das Template gefüllt werden soll */ var name = new { firstname = FIRST_NAME_VALUE, lastname = LAST_NAME_VALUE }; var user = new { // ReSharper disable once RedundantAnonymousTypePropertyName : Readability name = name }; var app = new { name = APPLICATION_NAME_VALUE, year = APPLICATION_YEAR_VALUE }; ModelMap model = new ModelMap(); model.Add("user", user); model.Add("application", app); string result = new Templater().FormatTemplate(TEMPLATE, model); /* Then: Müssen die Platzhalter korrekt ersetzt werden. */ Assert.AreEqual(expectedString, result); }
public void TestFormatPathNotFoundDefaultNull() { /* Given: Ein Template mit zwei Platzhaltern, von denen im Model nur ein Pfad gefunden werden kann. */ const string TEMPLATE = "Heute ist der {today:d}. Weltuntergang ist am {doomsday:d}"; DateTime now = DateTime.Now; string expected = TEMPLATE.Replace("{today:d}", now.ToString("d")); ModelMap model = new ModelMap(); model.Add("today", now); /* When: Das Template ersetzt werden soll */ string result = new Templater().FormatTemplate(TEMPLATE, model); /* Then: Muss das gefundene ersetzt werden und das andere so belassen werden. */ Assert.AreEqual(expected, result); }
public void TestFormat() { /* Given: Ein Template, in welches ein Datum eingefügt werden soll. */ const string TEMPLATE = "Heute ist der {today:d}"; DateTime now = DateTime.Now; string expected = TEMPLATE.Replace("{today:d}", now.ToString("d")); ModelMap model = new ModelMap(); model.Add("today", now); /* When: Die Platzhalter ersetzt werden sollen */ string result = new Templater().FormatTemplate(TEMPLATE, model); /* Then: Muss das korrekte Datum im richtigen Format eingefügt wurden sein. */ Assert.AreEqual(expected, result); }
public void TestSimpleTemplate() { /* Given: Ein einfacher String mit einem Platzhalter */ const string TEMPLATE = "Das ist ein {value} Template"; const string PLACE_HOLDER_VALUE = "einfaches"; string expectedString = TEMPLATE.Replace("{value}", PLACE_HOLDER_VALUE); ModelMap model = new ModelMap(); model.Add("value", PLACE_HOLDER_VALUE); /* When: Das Template mit dem Platzhalter gefüllt werden soll */ string result = new Templater().FormatTemplate(TEMPLATE, model); /* Then: Muss der Platzhalter korrekt ersetzt werden. */ Assert.AreEqual(expectedString, result); }
public void SendPeanutUpdateNotification(Peanut peanut, PeanutDto dtoBeforeUpdate, IList <PeanutRequirement> requirementsBeforeUpdate, string updateComment, PeanutUpdateNotificationOptions notificationOptions, User user) { Require.NotNull(peanut, "peanut"); Require.NotNull(notificationOptions, "notificationOptions"); string[] differences = peanut.GetDto() - dtoBeforeUpdate; StringBuilder updateSummary = new StringBuilder(); if (differences != null && differences.Any()) { foreach (string difference in differences) { updateSummary.AppendLine(difference); } } else { updateSummary.AppendLine("-"); } if (string.IsNullOrWhiteSpace(updateComment)) { updateComment = "-"; } foreach (PeanutParticipation peanutParticipation in FindParticipatorsToNotifyOnUpdate(peanut, user)) { ModelMap modelMap = new ModelMap(); modelMap.Add("peanut", peanut); modelMap.Add("peanutSourceName", dtoBeforeUpdate.Name); modelMap.Add("peanutSourceDay", dtoBeforeUpdate.Day); modelMap.Add("editor", user); modelMap.Add("recipient", peanutParticipation.UserGroupMembership.User); modelMap.Add("participation", peanutParticipation); modelMap.Add("peanutUrl", notificationOptions.PeanutUrl); modelMap.Add("updateSummary", updateSummary); modelMap.Add("comment", updateComment); MailMessage mailMessage = EmailService.CreateMailMessage(peanutParticipation.UserGroupMembership.User.Email, modelMap, "PeanutUpdated"); EmailService.SendMessage(mailMessage); } }
public void TestFormatCulture() { /* Given: Eine Zeichenfolge, in welches ein Datum im englischen Format eingefügt werden soll. */ const string TEMPLATE = "Heute ist der {today:d}"; DateTime now = DateTime.Now; CultureInfo englishCulture = CultureInfo.GetCultureInfo("en"); string expected = TEMPLATE.Replace("{today:d}", now.ToString("d", englishCulture)); ModelMap model = new ModelMap(); model.Add("today", now); /* When: Die Platzhalter ersetzt werden sollen */ string result = new Templater(englishCulture).FormatTemplate(TEMPLATE, model); /* Then: Muss das Datum korrekt im englischen Datumsformat eingefügt sein. */ Assert.AreEqual(expected, result); }
public void TestReplaceTwice() { /* Given: Ein Template in dem ein Platzhalter mehrfach vorkommt. */ const string TEMPLATE = "{hello}, {hello}, {hello}. Wie geht's?"; const string HELLO_VALUE = "Hi"; string expected = TEMPLATE.Replace("{hello}", HELLO_VALUE); ModelMap model = new ModelMap(); model.Add("hello", HELLO_VALUE); /* When: Die Platzhalter ersetzt werden sollen */ string result = new Templater().FormatTemplate(TEMPLATE, model); /* Then: Müssen alle Platzhalter ersetzt werden. */ Assert.AreEqual(expected, result); }
public void TestDeepPathTemplate() { /* Given: Ein Template mit einem 3-teiligen Platzhalter-Pfad */ const string TEMPLATE = "Das ist ein {user.name.firstname} Template"; const string PLACE_HOLDER_VALUE = "Tobias"; string expectedString = TEMPLATE.Replace("{user.name.firstname}", PLACE_HOLDER_VALUE); /* When: Das Template gefüllt werden soll */ var name = new { firstname = PLACE_HOLDER_VALUE }; // ReSharper disable once RedundantAnonymousTypePropertyName : Readability var user = new { name = name }; ModelMap model = new ModelMap(); model.Add("user", user); string result = new Templater().FormatTemplate(TEMPLATE, model); /* Then: Müssen die Platzhalter korrekt ersetzt werden. */ Assert.AreEqual(expectedString, result); }