public async Task <CreateOrderResult> Execute(WorkOrder workOrder)
        {
            using (_logger.BeginScope(Guid.NewGuid()))
            {
                ValidateRequest(workOrder);
                AttachUserInformation(workOrder);
                workOrder.DateRaised = DateTime.UtcNow;

                await SetStatus(workOrder);

                await PopulateRateScheduleItems(workOrder);

                var id = await _repairsGateway.CreateWorkOrder(workOrder);

                _logger.LogInformation(Resources.CreatedWorkOrder);

                var notification = await NotifyHandlers(workOrder);

                var result = new CreateOrderResult(id, workOrder.StatusCode, workOrder.GetStatus());

                _logger.LogInformation("Notification sent successfully for work order {workOrderId}", workOrder.Id);

                if (await workOrder.ContractorUsingDrs(_scheduleOfRatesGateway))
                {
                    _logger.LogInformation("Contractor using DRS: {workOrderId}", workOrder.Id);

                    result.ExternallyManagedAppointment = true;
                    var managementUri = new UriBuilder(_drsOptions.Value.ManagementAddress)
                    {
                        Port  = -1,
                        Query = $"tokenId={notification?.TokenId?.ToString()}"
                    };
                    result.ExternalAppointmentManagementUrl = managementUri.Uri;
                    workOrder.ExternalSchedulerReference    = notification?.TokenId;
                    await _repairsGateway.SaveChangesAsync();
                }

                _logger.LogInformation("Successfully created work order {workOrderId}", workOrder.Id);

                return(result);
            }
        }
Example #2
0
        public async Task <bool> ValidateWorkOrder(WorkOrder wo)
        {
            const int PlannedPriorityCode = 9;

            if (!await wo.ContractorUsingDrs(_scheduleOfRatesGateway))
            {
                _logger.LogInformation($"Work order {wo.Id} not saved to DRS because contractor does not use DRS");
                return(false);
            }

            if (wo.WorkPriority.PriorityCode == PlannedPriorityCode)
            {
                _logger.LogInformation($"Work order {wo.Id} not saved to DRS because it is planned priority");
                return(false);
            }

            _logger.LogInformation($"Updating WorkOrder: {wo.Id}");

            return(true);
        }
 private async Task <bool> UseDrs(WorkOrder workOder)
 {
     return(!await _featureManager.IsEnabledAsync(FeatureFlags.DRSIntegration) ||
            !await workOder.ContractorUsingDrs(_scheduleOfRatesGateway));
 }