示例#1
0
        public async System.Threading.Tasks.Task Merge(int masterTaskId, int[] slaveTasksIds, int workspaceId, string userAgent = "TogglAPI.Net")
        {
            var reportService    = new ReportServiceAsync(this.ToggleSrv);
            var timeEntryService = new TimeEntryServiceAsync(this.ToggleSrv);

            var reportParams = new DetailedReportParams()
            {
                UserAgent   = userAgent,
                WorkspaceId = workspaceId,
                TaskIds     = string.Join(",", slaveTasksIds.Select(id => id.ToString())),
                Since       = DateTime.Now.AddYears(-1).ToIsoDateTimeStr()
            };

            var result = await reportService.Detailed(reportParams);

            if (result.TotalCount > result.PerPage)
            {
                result = await reportService.FullDetailedReport(reportParams);
            }

            foreach (var reportTimeEntry in result.Data)
            {
                var timeEntry = await timeEntryService.Get(reportTimeEntry.Id.Value);

                timeEntry.TaskId = masterTaskId;
                var editedTimeEntry = await timeEntryService.Edit(timeEntry);

                if (editedTimeEntry == null)
                {
                    throw new ArgumentNullException(string.Format("Can't edit timeEntry #{0}", reportTimeEntry.Id));
                }
            }

            foreach (var slaveTaskId in slaveTasksIds)
            {
                if (!await Delete(slaveTaskId))
                {
                    throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId));
                }
            }
        }
        public async System.Threading.Tasks.Task Merge(int masterTaskId, int[] slaveTasksIds, int workspaceId, string userAgent = "TogglAPI.Net")
		{
			var reportService = new ReportServiceAsync(this.ToggleSrv);
			var timeEntryService = new TimeEntryServiceAsync(this.ToggleSrv);

			var reportParams = new DetailedReportParams()
			{
				UserAgent = userAgent,
				WorkspaceId = workspaceId,
				TaskIds = string.Join(",", slaveTasksIds.Select(id => id.ToString())),
				Since = DateTime.Now.AddYears(-1).ToIsoDateStr()
			};

			var result = await reportService.Detailed(reportParams);

			if (result.TotalCount > result.PerPage)
				result = await reportService.FullDetailedReport(reportParams);

			foreach (var reportTimeEntry in result.Data)
			{
				var timeEntry = await timeEntryService.Get(reportTimeEntry.Id.Value);
				timeEntry.TaskId = masterTaskId;
				var editedTimeEntry = await timeEntryService.Edit(timeEntry);
				if (editedTimeEntry == null)
					throw new ArgumentNullException(string.Format("Can't edit timeEntry #{0}", reportTimeEntry.Id));
			}

			foreach (var slaveTaskId in slaveTasksIds)
			{
				if (! await Delete(slaveTaskId))
					throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId));	
			}			
		}