Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        private bool HasPeanutChanged(Peanut peanut, PeanutDto peanutDto, IList <RequirementDto> requirements)
        {
            if (!peanut.GetDto().Equals(peanutDto))
            {
                /*Es gab Änderungen an den allgemeinen Daten des Peanuts.*/
                return(true);
            }

            IList <RequirementDto> requirementsBefore = peanut.Requirements.Select(r => r.GetDto()).ToList();

            if (requirementsBefore.Except(requirements).Any())
            {
                /*Anforderungen wurden gelöscht*/
                return(true);
            }
            if (requirements.Except(requirementsBefore).Any())
            {
                /*Anforderungen wurden hinzugefügt*/
                return(true);
            }

            return(false);
        }