public async Task InitializeIncident(IOperation operation, IncidentUpdateEntity entity) { await operation.Connection.ExecuteAsync(entity, @" INSERT INTO [portal].[Incident] ( [OperationId], [AuthorId], [AssigneeId] ) VALUES ( @IncidentOperationId, @AuthorId, @AssigneeId ); INSERT INTO [portal].[IncidentHistory] ( [OperationId], [AuthorId], [AssigneeId], [IsUnassigned], [StatusId], [ChangedBy], [Comment] ) VALUES ( @IncidentOperationId, @AuthorId, @AssigneeId, IIF(@AssigneeId IS NULL, 0, 1), 1, @ChangedBy, @Comment ); "); }
public async Task InitializeIncident(IOperation operation, IncidentUpdateEntity entity) { if (await incidentStore.IsIncidentExist(operation, entity.IncidentOperationId)) { throw CommonExceptions.IncidentAlreadyExists(operation, entity.IncidentOperationId); } if (!await operationStore.IsOperationExist(operation, entity.IncidentOperationId)) { throw CommonExceptions.OperationWasNotFound(operation, entity.IncidentOperationId); } await incidentStore.InitializeIncident(operation, entity); }
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 ); "); }
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); }