public void UpdateModel(ProjectUpdateConfiguration projectUpdateConfiguration)
 {
     projectUpdateConfiguration.ProjectUpdateKickOffDate          = ProjectUpdateKickOffDate;
     projectUpdateConfiguration.ProjectUpdateCloseOutDate         = ProjectUpdateCloseOutDate;
     projectUpdateConfiguration.ProjectUpdateReminderInterval     = ProjectUpdateReminderInterval;
     projectUpdateConfiguration.EnableProjectUpdateReminders      = EnableProjectUpdateReminders.GetValueOrDefault(); // will never be null
     projectUpdateConfiguration.SendPeriodicReminders             = SendPeriodicReminders.GetValueOrDefault();        // will never be null
     projectUpdateConfiguration.SendCloseOutNotification          = SendCloseOutNotification.GetValueOrDefault();     // will never be null
     projectUpdateConfiguration.ProjectUpdateKickOffIntroContent  = ProjectUpdateKickOffIntroContent?.ToString();
     projectUpdateConfiguration.ProjectUpdateReminderIntroContent =
         ProjectUpdateReminderIntroContent?.ToString();
     projectUpdateConfiguration.ProjectUpdateCloseOutIntroContent =
         ProjectUpdateCloseOutIntroContent?.ToString();
 }
Example #2
0
 public void UpdateModel(ProjectUpdateSetting projectUpdateSetting)
 {
     projectUpdateSetting.ProjectUpdateKickOffDate          = ProjectUpdateKickOffDate;
     projectUpdateSetting.ProjectUpdateCloseOutDate         = ProjectUpdateCloseOutDate;
     projectUpdateSetting.ProjectUpdateReminderInterval     = ProjectUpdateReminderInterval;
     projectUpdateSetting.EnableProjectUpdateReminders      = EnableProjectUpdateReminders.GetValueOrDefault(); // will never be null
     projectUpdateSetting.SendPeriodicReminders             = SendPeriodicReminders.GetValueOrDefault();        // will never be null
     projectUpdateSetting.SendCloseOutNotification          = SendCloseOutNotification.GetValueOrDefault();     // will never be null
     projectUpdateSetting.ProjectUpdateKickOffIntroContent  = ProjectUpdateKickOffIntroContent?.ToString();
     projectUpdateSetting.ProjectUpdateReminderIntroContent =
         ProjectUpdateReminderIntroContent?.ToString();
     projectUpdateSetting.ProjectUpdateCloseOutIntroContent =
         ProjectUpdateCloseOutIntroContent?.ToString();
     projectUpdateSetting.DaysBeforeCloseOutDateForReminder = DaysBeforeCloseOutDateForReminder;
 }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // these bools will never be null due to RequiredAttribute
            if (EnableProjectUpdateReminders ?? false)
            {
                if (string.IsNullOrWhiteSpace(ProjectUpdateKickOffIntroContent?.ToString()))
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, HtmlString>(
                                     $"You must provide {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Kick-Off Email Content if {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Reminders are enabled.",
                                     m => m.ProjectUpdateKickOffIntroContent));
                }
                if (!ProjectUpdateKickOffDate.HasValue)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, DateTime?>(
                                     $"You must provide a {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Kick-Off Date if {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Reminders are enabled.",
                                     m => m.ProjectUpdateKickOffDate));
                }
                else if (ProjectUpdateKickOffDate.Value < DateTime.Today)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, DateTime?>(
                                     $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Kick-Off Date cannot be in the past.", m => m.ProjectUpdateKickOffDate));
                }
            }

            if (SendPeriodicReminders ?? false)
            {
                if (string.IsNullOrWhiteSpace(ProjectUpdateReminderIntroContent?.ToString()))
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, HtmlString>(
                                     $"You must provide {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Reminder Email Content if Periodic Reminders are enabled.",
                                     m => m.ProjectUpdateReminderIntroContent));
                }

                if (!ProjectUpdateReminderInterval.HasValue)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, int?>(
                                     $"You must provide a {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Reminder Interval if Periodic Reminders are enabled.",
                                     m => m.ProjectUpdateReminderInterval));
                }
                else if (ProjectUpdateReminderInterval.Value < 7)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, int?>(
                                     $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Reminder Interval must be at least 7 days.",
                                     m => m.ProjectUpdateReminderInterval));
                }
                else if (ProjectUpdateReminderInterval > 365)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, int?>(
                                     $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Reminder Interval cannot be greater than 365 days.",
                                     m => m.ProjectUpdateReminderInterval));
                }
            }

            if (SendCloseOutNotification ?? false)
            {
                if (string.IsNullOrWhiteSpace(ProjectUpdateCloseOutIntroContent?.ToString()))
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, HtmlString>(
                                     $"You must provide {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Close-Out Email Content if {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Close-Out Notifications are enabled.",
                                     m => m.ProjectUpdateCloseOutIntroContent));
                }
                if (!ProjectUpdateCloseOutDate.HasValue)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, DateTime?>(
                                     $"You must provide a {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Close-Out Date if {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Close-Out Notifications are enabled.",
                                     m => m.ProjectUpdateCloseOutDate));
                }
                else if (ProjectUpdateKickOffDate.HasValue)
                {
                    if (!EnableProjectUpdateReminders ?? false)
                    {
                        yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, DateTime?>(
                                         $"You cannot set a {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Close-Out Date without also setting a {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Kick-Off Date",
                                         m => m.ProjectUpdateCloseOutDate));
                    }
                    if (ProjectUpdateKickOffDate.Value.AddYears(1) < ProjectUpdateCloseOutDate.Value)
                    {
                        yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, DateTime?>(
                                         $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Close-Out Date cannot be more than 1 year later than {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Kick-Off Date.",
                                         m => m.ProjectUpdateCloseOutDate));
                    }
                    if (ProjectUpdateKickOffDate.Value >= ProjectUpdateCloseOutDate.Value)
                    {
                        yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, DateTime?>(
                                         $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Close-Out Date must be later than {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Kick-Off Date.",
                                         m => m.ProjectUpdateCloseOutDate));
                    }
                    if (ProjectUpdateCloseOutDate.Value < DateTime.Today)
                    {
                        yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, DateTime?>(
                                         $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update Close-Out Date cannot be in the past.", m => m.ProjectUpdateKickOffDate));
                    }
                }
            }
        }
Example #4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // these bools will never be null due to RequiredAttribute
            var fieldDefinitionLabelProject = FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel();

            if (EnableProjectUpdateReminders ?? false)
            {
                if (string.IsNullOrWhiteSpace(ProjectUpdateKickOffIntroContent?.ToString()))
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, HtmlString>(
                                     $"You must provide {fieldDefinitionLabelProject} Update Kick-off Email Content if {fieldDefinitionLabelProject} Update Reminders are enabled.",
                                     m => m.ProjectUpdateKickOffIntroContent));
                }
            }

            if (SendPeriodicReminders ?? false)
            {
                if (string.IsNullOrWhiteSpace(ProjectUpdateReminderIntroContent?.ToString()))
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, HtmlString>(
                                     $"You must provide {fieldDefinitionLabelProject} Update Reminder Email Content if Periodic Reminders are enabled.",
                                     m => m.ProjectUpdateReminderIntroContent));
                }

                if (!ProjectUpdateReminderInterval.HasValue)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, int?>(
                                     $"You must provide a {fieldDefinitionLabelProject} Update Reminder Interval if Periodic Reminders are enabled.",
                                     m => m.ProjectUpdateReminderInterval));
                }
                else if (ProjectUpdateReminderInterval.Value < 7)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, int?>(
                                     $"{fieldDefinitionLabelProject} Update Reminder Interval must be at least 7 days.",
                                     m => m.ProjectUpdateReminderInterval));
                }
                else if (ProjectUpdateReminderInterval > 365)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, int?>(
                                     $"{fieldDefinitionLabelProject} Update Reminder Interval cannot be greater than 365 days.",
                                     m => m.ProjectUpdateReminderInterval));
                }
            }

            if (SendCloseOutNotification ?? false)
            {
                if (string.IsNullOrWhiteSpace(ProjectUpdateCloseOutIntroContent?.ToString()))
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, HtmlString>(
                                     $"You must provide {fieldDefinitionLabelProject} Update Close-out Email Content if {fieldDefinitionLabelProject} Update Close-out Reminders are enabled.",
                                     m => m.ProjectUpdateCloseOutIntroContent));
                }
                if (!DaysBeforeCloseOutDateForReminder.HasValue)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, int?>(
                                     $"You must provide the Days before end date to send Close-out Reminder if {fieldDefinitionLabelProject} Update Close-out Reminders are enabled.",
                                     m => m.ProjectUpdateReminderInterval));
                }
                if (DaysBeforeCloseOutDateForReminder.HasValue && DaysBeforeCloseOutDateForReminder > 365)
                {
                    yield return(new SitkaValidationResult <EditProjectUpdateConfigurationViewModel, int?>(
                                     "Days before end date to send Close-out Reminder cannot be greater than 365 days.",
                                     m => m.DaysBeforeCloseOutDateForReminder));
                }
            }
        }