public async Task <bool> RemoveAsync(PublishedProject publishedProject, PublishedAssignment publishedAssignment) { if (publishedProject == null) { throw new ArgumentNullException(nameof(publishedProject)); } if (publishedAssignment == null) { throw new ArgumentNullException(nameof(publishedAssignment)); } bool result = false; try { _projectContext.Load(publishedProject.Assignments); await _projectContext.ExecuteQueryAsync(); if (publishedProject.Assignments.Any(ass => ass.Id == publishedAssignment.Id)) { // Ensure I have it check it out await _projectClient.CheckInAsync(publishedProject); var draftProject = await _projectClient.CheckOutAsync(publishedProject); _projectContext.Load(draftProject.Assignments); var draftAssignments = _projectContext .LoadQuery(draftProject.Assignments.Where(ass => ass.Id == publishedAssignment.Id)); await _projectContext.ExecuteQueryAsync(); var draftAssignment = draftAssignments.First(); var clientResult = draftProject.Assignments.Remove(draftAssignment); await _projectClient.PublishAndUpdate(draftProject, publishedProject.Name); await _projectClient.CheckInAsync(publishedProject); result = clientResult.Value; } } catch (Exception ex) { // TODO: LOG ERROR! throw new CsomClientException($"Unexcepted error removing an assignment. " + $"Assignment id is {publishedAssignment.Id}. " + $"Published project name is {publishedProject.Name}. " + $"Project context url is {_projectContext.Url}.", ex); } return(result); }
public async Task <PublishedAssignment> GetByIdAsync(PublishedProject publishedProject, Guid id) { if (publishedProject == null) { throw new ArgumentNullException(nameof(publishedProject)); } if (id == null) { throw new ArgumentNullException(nameof(id)); } PublishedAssignment assignment = null; try { IEnumerable <PublishedAssignment> publishedAssignments = _projectContext.LoadQuery( publishedProject.Assignments.Where(a => a.Id == id)); await _projectContext.ExecuteQueryAsync(); if (publishedAssignments.Any()) { assignment = publishedAssignments.FirstOrDefault(); // We need this in order to be able to locate the task the assigment belongs to _projectContext.Load(assignment.Task); await _projectContext.ExecuteQueryAsync(); } } catch (Exception ex) { // TODO: LOG ERROR! throw new CsomClientException($"Unexcepted error getting an assignment by id. " + $"id searched is {id}. " + $"Published task name is {publishedProject.Name}. " + $"Project context url is {_projectContext.Url}.", ex); } return(assignment); }