Esempio n. 1
0
		public void Merge(int masterTaskId, int[] slaveTasksIds, int workspaceId, string userAgent = "TogglAPI.Net")
		{
			var reportService = new ReportService(this.ToggleSrv);
			var timeEntryService = new TimeEntryService(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 = reportService.Detailed(reportParams);

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

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

			foreach (var slaveTaskId in slaveTasksIds)
			{
				if (!Delete(slaveTaskId))
					throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId));	
			}			
		}
Esempio n. 2
0
		public void Merge(int masterTaskId, int slaveTaskId, int workspaceId, string userAgent = "TogglAPI.Net")
	    {
		    var reportService = new ReportService(this.ToggleSrv);
		    var timeEntryService = new TimeEntryService(this.ToggleSrv);

			var reportParams = new DetailedReportParams()
								{
									UserAgent = userAgent,
									WorkspaceId = workspaceId,
									TaskIds = slaveTaskId.ToString(),
									Since = DateTime.Now.AddYears(-1).ToIsoDateStr()
								};

		    var result = reportService.Detailed(reportParams);

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

		    foreach (var reportTimeEntry in result.Data)
		    {
			    var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value);
				timeEntry.TaskId = masterTaskId;
			    try
			    {
				    var editedTimeEntry = timeEntryService.Edit(timeEntry);
			    }
			    catch (Exception ex)
			    {
				    var res = ex.Data;
			    }			    
		    }

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