protected virtual async Task OnIssueCreated(IssueCreatedEventArgs args, CancellationToken token) { if (args == null) { throw new ArgumentNullException("args"); } if (string.IsNullOrWhiteSpace(args.ReferenceId)) { throw new ArgumentException("ReferenceId cannot be empty"); } using (LogContext.PushProperty("IssueId", args.ReferenceId)) { int?userId; try { userId = string.IsNullOrWhiteSpace(args.RequestorEmail) ? null : await GetOrCreateUserIdAsync(args.RequestorEmail, args.RequestorGivenName, args.RequestorSurnName, args.RequestorTelephone); } catch (Exception err) { userId = null; _logger.Warning(err, "Error retrieving user details for {EmailAddress}", args.RequestorEmail); } int ownerPersonId = userId.GetValueOrDefault(); Issue oldIssue = null; oldIssue = await GetIssueByIncidentId(args.ReferenceId); if (oldIssue != null) { _logger.Information("Found Issue {IssueId} in database, old status {IssueStatus}, new status {newIssueStatus}", args.ReferenceId, oldIssue.RemedyStatus, args.RemedyStatus); await _issueRepository.DeleteIssueAsync(oldIssue, token); } try { var issue = Issue.Create(args.Title, args.Description, args.ReferenceId, args.RemedyStatus, args.RequestorDisplayName, args.AssigneeEmail, args.AssigneeGroup, args.CreatedDate, args.Urgency, ownerPersonId); _logger.Information("Saving Issue {IssueId} to database", args.ReferenceId); await _issueRepository.AddIssueAsync(issue, token); } catch (Exception err) { _logger.Error(err, "Unable to set work item id to Issue. Will retry later. Error was: {ErrorMessage}", err.Message); throw; } } }
/// <summary> /// Deletes the specified Issue. /// </summary> /// <param name="publicProjectId">The public ID of the Project.</param> /// <param name="publicIssueId">The public ID of the Issue.</param> /// <returns>An awaitable Task.</returns> public async Task DeleteIssueAsync(Guid publicProjectId, Guid publicIssueId) { //get Project Project project = await projectRepository.GetProjectAsync(publicProjectId); if (project == null) { throw new NotFoundException(); } //get Issue Issue issueToDelete = await issueRepository.GetIssueAsync(publicIssueId); if (issueToDelete == null) { throw new NotFoundException(); } //delete Issue await issueRepository.DeleteIssueAsync(publicIssueId); }