public async Task UpdateIncident(IOperation operation, IncidentUpdateEntity entity) { if (!await incidentStore.IsIncidentExist(operation, entity.IncidentOperationId)) { throw CommonExceptions.IncidentWasNotFound(operation, entity.IncidentOperationId); } var previous = await incidentStore.GetIncident(operation, entity.IncidentOperationId); var history = new IncidentHistoryRecordEntity(); if (previous.AuthorId != entity.AuthorId) { history.AuthorId = entity.AuthorId; } if (previous.AssigneeId != entity.AssigneeId) { if (entity.AssigneeId == null) { history.IsUnassigned = true; } if (previous.AssigneeId == null) { history.IsUnassigned = false; } history.AssigneeId = entity.AssigneeId; } if (previous.Status != entity.Status) { history.Status = entity.Status; } await incidentStore.UpdateIncident(operation, entity, history); }
public async Task UpdateIncident(IOperation operation, IncidentUpdateEntity entity, IncidentHistoryRecordEntity history) { await operation.Connection.ExecuteAsync(new { entity.IncidentOperationId, OriginalAuthorId = entity.AuthorId, OriginalAssigneeId = entity.AssigneeId, OriginalStatus = entity.Status, HistoricalAuthorId = history.AuthorId, HistoricalAssigneeId = history.AssigneeId, history.IsUnassigned, HistoricalStatus = history.Status, entity.ChangedBy, entity.Comment }, @" UPDATE pin SET pin.[AuthorId] = @OriginalAuthorId, pin.[AssigneeId] = @OriginalAssigneeId, pin.[StatusId] = @OriginalStatus FROM [portal].[Incident] pin WHERE pin.[OperationId] = @IncidentOperationId; INSERT INTO [portal].[IncidentHistory] ( [OperationId], [AuthorId], [AssigneeId], [IsUnassigned], [StatusId], [ChangedBy], [Comment] ) VALUES ( @IncidentOperationId, @HistoricalAuthorId, @HistoricalAssigneeId, @IsUnassigned, @HistoricalStatus, @ChangedBy, @Comment ); "); }