Exemplo n.º 1
0
        private static bool TodayIsReminderDayForProjectUpdateConfiguration(
            ProjectUpdateSetting projectUpdateSetting)
        {
            var projectUpdateKickOffDate  = FirmaDateUtilities.LastReportingPeriodStartDateForBackgroundJob(projectUpdateSetting.ProjectUpdateKickOffDate.GetValueOrDefault());
            var projectUpdateCloseOutDate = FirmaDateUtilities.LastReportingPeriodEndDateForBackgroundJob(projectUpdateSetting.ProjectUpdateKickOffDate.GetValueOrDefault(), projectUpdateSetting.ProjectUpdateCloseOutDate.GetValueOrDefault());
            var isReminderDay             = DateTime.Today != projectUpdateKickOffDate && (DateTime.Today - projectUpdateKickOffDate).Days % projectUpdateSetting.ProjectUpdateReminderInterval == 0;
            var isAfterCloseOut           = DateTime.Today.IsDateAfter(projectUpdateCloseOutDate);

            return(isReminderDay && !isAfterCloseOut);
        }
Exemplo n.º 2
0
        protected virtual void ProcessRemindersImpl()
        {
            Logger.Info($"Processing '{JobName}' notifications.");

            // we're "tenant-agnostic" right now
            var projectUpdateSettings = DbContext.AllProjectUpdateSettings.ToList();


            foreach (var projectUpdateSetting in projectUpdateSettings)
            {
                var notifications    = new List <Notification>();
                var tenantID         = projectUpdateSetting.TenantID;
                var databaseEntities = new DatabaseEntities(tenantID);
                var projects         = databaseEntities.Projects.ToList();

                var tenantAttribute = databaseEntities.TenantAttributes.Single();
                var reminderSubject = $"Time to update your {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabelPluralizedForBackgroundJob(tenantAttribute.TenantID)}";
                if (projectUpdateSetting.EnableProjectUpdateReminders)
                {
                    var projectUpdateKickOffDate = FirmaDateUtilities.LastReportingPeriodStartDateForBackgroundJob(projectUpdateSetting.ProjectUpdateKickOffDate.GetValueOrDefault());
                    if (DateTime.Today == projectUpdateKickOffDate)
                    {
                        notifications.AddRange(RunNotifications(projects, reminderSubject,
                                                                projectUpdateSetting.ProjectUpdateKickOffIntroContent, tenantAttribute));
                    }
                }

                if (projectUpdateSetting.SendPeriodicReminders)
                {
                    if (TodayIsReminderDayForProjectUpdateConfiguration(projectUpdateSetting))
                    {
                        notifications.AddRange(RunNotifications(projects, reminderSubject, projectUpdateSetting.ProjectUpdateReminderIntroContent, tenantAttribute));
                        // notifyOnAll is false b/c we only send periodic reminders for projects whose updates haven't been submitted yet.
                    }
                }

                if (projectUpdateSetting.SendCloseOutNotification)
                {
                    var closeOutReminderDate = FirmaDateUtilities.LastReportingPeriodEndDateForBackgroundJob(projectUpdateSetting.ProjectUpdateKickOffDate.GetValueOrDefault(), projectUpdateSetting.ProjectUpdateCloseOutDate.GetValueOrDefault());
                    if (projectUpdateSetting.DaysBeforeCloseOutDateForReminder.HasValue)
                    {
                        closeOutReminderDate = closeOutReminderDate.AddDays(-projectUpdateSetting.DaysBeforeCloseOutDateForReminder.Value);
                    }
                    if (DateTime.Today == closeOutReminderDate)
                    {
                        notifications.AddRange(RunNotifications(projects, reminderSubject,
                                                                projectUpdateSetting.ProjectUpdateCloseOutIntroContent, tenantAttribute));
                    }
                }

                databaseEntities.AllNotifications.AddRange(notifications);
                databaseEntities.SaveChangesWithNoAuditing(tenantID);
            }
        }