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); } } }
public ActionResult UpdateState(Peanut peanut, PeanutState peanutState, User currentUser) { Require.NotNull(peanut, "peanut"); Require.NotNull(currentUser, "currentUser"); string peanutUrl = Url.Action("Show", "Peanut", new { peanut = peanut.BusinessId }, Request.Url.Scheme); PeanutUpdateNotificationOptions peanutUpdateNotificationOptions = new PeanutUpdateNotificationOptions(true, peanutUrl); PeanutService.UpdateState(peanut, peanutState, peanutUpdateNotificationOptions, currentUser); return(RedirectToAction("Show", new { peanut = peanut.BusinessId })); }
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); } }
public void AddComment(Peanut peanut, string updateComment, PeanutUpdateNotificationOptions notificationOptions, User user) { Require.NotNull(peanut, "peanut"); Require.NotNull(user, "user"); Require.NotNull(notificationOptions, "notificationOptions"); Require.NotNullOrWhiteSpace(updateComment, "updateComment"); if (!string.IsNullOrWhiteSpace(updateComment)) { /*Wenn es einen Änderungskommentar gibt, dann diesen hinzufügen.*/ peanut.AddComment(updateComment, new EntityCreatedDto(user, DateTime.Now)); } if (notificationOptions.SendNotification) { NotificationService.SendPeanutCommentNotification(peanut, updateComment, notificationOptions, user); } }
public void Update(Peanut peanut, PeanutDto peanutDto, IList <RequirementDto> requirements, string updateComment, PeanutUpdateNotificationOptions notificationOptions, User user) { Require.NotNull(peanut, "peanut"); Require.NotNull(peanutDto, "peanutDto"); Require.NotNull(requirements, "requirements"); Require.NotNull(user, "user"); Require.NotNull(notificationOptions, "notificationOptions"); PeanutDto dtoBeforeUpdate = peanut.GetDto(); IList <PeanutRequirement> requirementsBeforeUpdate = peanut.Requirements; if (HasPeanutChanged(peanut, peanutDto, requirements)) { /*Es wurden Änderungen am Peanut vorgenommen!*/ peanut.Update(peanutDto, requirements, new EntityChangedDto(user, DateTime.Now)); if (!string.IsNullOrWhiteSpace(updateComment)) { /*Wenn es einen Änderungskommentar gibt, dann diesen hinzufügen.*/ peanut.AddComment(updateComment, new EntityCreatedDto(user, DateTime.Now)); } if (notificationOptions.SendNotification) { NotificationService.SendPeanutUpdateNotification(peanut, dtoBeforeUpdate, requirementsBeforeUpdate, updateComment, notificationOptions, user); } if (HaveRequirementsChanged(requirementsBeforeUpdate, requirements)) { NotificationService.SendPeanutUpdateRequirementsNotification(peanut, updateComment, new PeanutUpdateRequirementsNotificationOptions(notificationOptions.PeanutUrl), user); } } else if (!string.IsNullOrWhiteSpace(updateComment)) { /*Es wurde nur ein Kommentar hinterlassen*/ AddComment(peanut, updateComment, notificationOptions, user); } }
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 UpdateState(Peanut peanut, PeanutState peanutState, PeanutUpdateNotificationOptions notificationOptions, User user) { Require.NotNull(peanut, "peanut"); Require.NotNull(user, "user"); if (peanut.PeanutState == peanutState) { /*Keine Änderung am Status*/ return; } if (peanutState >= PeanutState.SchedulingDone && !peanut.IsFixed) { RemoveParticipations(peanut, peanut.Participations.Where(s => s.ParticipationState == PeanutParticipationState.Pending) .Select(s => s.UserGroupMembership) .ToList(), user); } peanut.UpdateState(peanutState, new EntityChangedDto(user, DateTime.Now)); NotificationService.SendPeanutUpdateStateNotification(peanut, notificationOptions, user); }