public async Task <bool> CreateAsync(InternalDeliveryRequest deliveryRequest)
        {
            var message = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(deliveryRequest)));

            try
            {
                // Send the message to the queue.
                await _queueClient.SendAsync(message);
            }
            catch (Exception e)
            {
                _logger.LogError("Error sending delivery request to service bus queue {errorMessage}", e.StackTrace);
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public async Task <IActionResult> CreateDeliveryRequestAsync([FromBody] DeliveryRequest deliveryRequest)
        {
            _logger.LogInformation("In Schedule action with delivery request: {deliveryRequest}", deliveryRequest);

            // Based on the delivery request received, construct an internal delivery request to pass around
            var deliveryId = Guid.NewGuid().ToString();
            var internalDeliveryRequest = new InternalDeliveryRequest(deliveryId,
                                                                      deliveryRequest.OwnerId,
                                                                      deliveryRequest.PickupLocation,
                                                                      deliveryRequest.DropoffLocation,
                                                                      deliveryRequest.PickupTime,
                                                                      deliveryRequest.Deadline,
                                                                      deliveryRequest.Expedited,
                                                                      deliveryRequest.ConfirmationRequired,
                                                                      deliveryRequest.PackageInfo);

            // Set the delivery id for the payload to return
            deliveryRequest.DeliveryId = deliveryId;
            var completed = await _deliveryRequestRepository.CreateAsync(internalDeliveryRequest);

            return(completed ? (IActionResult)CreatedAtRoute("CreateDeliveryRequest", new { id = deliveryRequest.DeliveryId }, deliveryRequest) : BadRequest("Delivery request failed. Check logs for exception details."));
        }