Пример #1
0
        public static void SetDueAndAdjustReminder(this ITask task, DateTime?newDate, IEnumerable <ITask> impactedTasks, bool showNotification = false)
        {
            INotificationService    notificationService = Ioc.Resolve <INotificationService>();
            ISynchronizationManager syncManager         = Ioc.Resolve <ISynchronizationManager>();

            var oldDate = task.Due;

            // change due date (and if we sync with Exchange, start date might be updated too)
            task.Due = newDate;
            syncManager.SetDueDate(newDate, task.Start, v => task.Start = v);
            task.Modified = DateTime.Now;

            // check if we must update reminder date
            if (!task.Alarm.HasValue || !newDate.HasValue || !oldDate.HasValue)
            {
                if (showNotification)
                {
                    if (newDate.HasValue)
                    {
                        var dateLong = string.Format("{0} {1}", newDate.Value.ToString("ddddd"), newDate.Value.ToString("M"));
                        notificationService.ShowNotification(string.Format(StringResources.Notification_DueDateUpdatedFormat, dateLong));
                    }
                    else
                    {
                        notificationService.ShowNotification(StringResources.Notification_DueDateRemoved);
                    }
                }

                return;
            }

            int days = (int)(newDate.Value - oldDate.Value).TotalDays;

            task.Alarm = task.Alarm.Value.AddDays(days);

            if (showNotification)
            {
                string newReminderDatetime = string.Format("{0} {1}", task.Alarm.Value.ToString("M"), task.Alarm.Value.ToString("t"));
                string toastMessage        = string.Format(StringResources.Dialog_ReminderUpdatedDateFormat, newReminderDatetime);
                if (impactedTasks.Count(t => t.Alarm.HasValue) > 1)
                {
                    toastMessage = StringResources.Dialog_RemindersUpdated;
                }

                notificationService.ShowNotification(toastMessage);
            }
        }