Example #1
0
        private List<Task> ToTaskList(RtmGetTasksResponse response)
        {
            //TODO: handle response failure
            if (!response.Status.ToLower().Equals("ok"))
                return null;

            var taskList = new List<Task>();
            foreach (var list in response.Tasks.List)
            {
                if (null == list.TaskSeries)
                    continue;

                foreach (var series in list.TaskSeries)
                {
                    var tags = new List<string>();
                    if (null != series.Tags) {
                        tags.AddRange(series.Tags);
                    }

                    var participants = new List<User>();
                    if (null != series.Participants) {
                        participants.AddRange(series.Participants.Select(participant => new User {
                            Id = participant.Id,
                            UserName = participant.UserName,
                            FullName = participant.FullName
                        }));
                    }

                    var notes = new List<Note>();
                    if (null != series.Notes) {
                        notes.AddRange(series.Notes.Select(note => new Note {
                            Id = note.Id,
                            Text = note.Text,
                            Title = note.Title,
                            Created = note.Created.AsNullableDateTime(null),
                            Modified = note.Modified.AsNullableDateTime(null)
                        }));
                    }

                    var rootList = list;
                    var rootSeries = series;
                    taskList.AddRange(series.Tasks.Select(task => new Task {
                        ListId = rootList.Id,
                        TaskSeriesId = rootSeries.Id,
                        Created = rootSeries.Created.AsNullableDateTime(null),
                        Modified = rootSeries.Modified.AsNullableDateTime(null),
                        Name = rootSeries.Name,
                        Source = rootSeries.Source,
                        Url = rootSeries.Url,
                        LocationId = rootSeries.LocationId,
                        Tags = tags,
                        Participants = participants,
                        Notes = notes,
                        Id = task.Id,
                        Due = task.Due.AsNullableDateTime(null),
                        HasDueTime = task.HasDueTime.AsBool(false),
                        Added = task.Added.AsNullableDateTime(null),
                        Completed = task.Completed.AsNullableDateTime(null),
                        Deleted = task.Deleted.AsNullableDateTime(null),
                        Priority = task.Priority.AsInt(0),
                        Postponed = task.Postponed.AsInt(0),
                        Estimate = task.Estimate.AsNullableDateTime(null),
                        IsRepeating = rootSeries.Tasks.Count > 0
                    }));
                }
            }

            return taskList;
        }