protected bool UpdateTask(ITask task) { task.Title = this.Title; // this should never happens but... if (this.TargetFolder == null) { return(false); } task.Folder = this.TargetFolder; if (this.TargetContext != null && !string.IsNullOrEmpty(this.TargetContext.Name) && this.TargetContext.Name != " ") { task.Context = this.TargetContext; } else { task.Context = null; } task.Note = this.Note; task.Priority = this.Priority; task.Due = this.DueDate; task.Progress = this.Progress; if (this.StartDate.HasValue) { task.Start = this.Start; } else { task.Start = null; } if (this.ReminderDate.HasValue) { task.Alarm = this.Reminder; } else { task.Alarm = null; } if (this.selectedFrequency != null) { task.CustomFrequency = this.selectedFrequency.CustomFrequency; task.UseFixedDate = this.selectedFrequency.UseFixedDate; } else { task.CustomFrequency = null; } // check deleted subtasks foreach (var subtask in task.Children.ToList()) { bool stillExists = this.subtasks.Any(t => t.Id == subtask.Id); if (!stillExists) { task.RemoveChild(subtask); subtask.Delete(); } } // check new and updated subtasks foreach (var subtask in this.subtasks) { bool updated = false; if (subtask.Id > 0) { var existing = task.Children.FirstOrDefault(t => t.Id == subtask.Id); if (existing != null) { existing.Folder = this.targetFolder; existing.IsCompleted = subtask.IsCompleted; existing.Title = subtask.Title; updated = true; } } if (!updated) { task.AddChild(subtask); subtask.Folder = this.targetFolder; } } task.WriteTags(this.Tags); task.Modified = DateTime.Now; task.IsCompleted = this.IsCompleted; return(true); }