public async Task <WorkOrderResponse> Execute(int id) { var workOrder = await _repairsGateway.GetWorkOrder(id); var manuallyAssignedOperatives = workOrder.HasManuallyAssignedOperatives(); if (await _featureManager.IsEnabledAsync(FeatureFlags.UpdateOperativesOnWorkOrderGet) && await _featureManager.IsEnabledAsync(FeatureFlags.DRSIntegration) && await workOrder.ContractorUsingDrs(_sorGateway) && workOrder.StatusCode == WorkStatusCode.Open && !manuallyAssignedOperatives) { _logger.LogInformation($"Calling DrsService.UpdateWorkOrderDetails from GetWorkOrderUseCase for {workOrder.Id}"); try { await _drsService.UpdateWorkOrderDetails(id); } catch (Exception e) { _logger.LogError(e, $"Failed to update work order {id} from DRS"); try { if (e.Message.Contains("Unable to find order in OptiTime Web")) { _logger.LogError(e, $"Couldn't find workorder, creating {id} instead DRS"); await _drsService.CreateOrder(workOrder); } } catch (Exception) { //swallow exceptions for create } } } var appointment = await _appointmentGateway.GetAppointment(workOrder.Id); var canAssignOperative = await workOrder.CanAssignOperative(_sorGateway); var workOrderResponse = workOrder.ToResponse(appointment, _drsOptions.Value.ManagementAddress, canAssignOperative); var tasks = await _repairsGateway.GetWorkOrderTasksForWorkOrder(workOrder); workOrderResponse.TotalSMVs = tasks is null ? 0 : tasks.Sum(t => t.StandardMinuteValue * t.Quantity); return(workOrderResponse); }
public async Task <string> ConfirmBooking(bookingConfirmation bookingConfirmation) { _logger.LogInformation($"ConfirmBooking for bookingId: {bookingConfirmation.bookingId}"); var serialisedBookings = JsonConvert.SerializeObject(bookingConfirmation); _logger.LogInformation(serialisedBookings); var workOrderId = (int)bookingConfirmation.primaryOrderNumber; await _appointmentsGateway.SetTimedBooking( workOrderId, bookingConfirmation.planningWindowStart, bookingConfirmation.planningWindowEnd, bookingConfirmation.bookingReason ); await _drsService.UpdateWorkOrderDetails(workOrderId); await AddAuditTrail(workOrderId, bookingConfirmation); return(Resources.DrsBackgroundService_BookingAccepted); }
private async Task <bool> UpdateWorkOrderDetails(int workOrderId) { var wo = await _repairsGateway.GetWorkOrder(workOrderId); if (!await ValidateWorkOrder(wo)) { return(false); } try { await _drsService.UpdateWorkOrderDetails(workOrderId); } catch (ApiException e) { // Catch API exceptions from DRS as we dont want to potentially fail updating other work orders // when there is a problem in DRS with one of them _logger.LogInformation($"Failed to update workOrder {workOrderId}: {e.Message}"); return(false); } return(true); }