Esempio n. 1
0
        public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "update-status")] HttpRequest request, ILogger logger)
        {
            logger.LogInformation("Shipment webhook arrived with an update");

            string requestBody          = await new StreamReader(request.Body).ReadToEndAsync();
            var    shipmentStatusUpdate = JsonConvert.DeserializeObject <ShipmentStatusUpdate>(requestBody);

            if (shipmentStatusUpdate == null)
            {
                return(new BadRequestResult());
            }

            logger.LogInformation("Shipment {TrackingNumber} has changed to {Status}", shipmentStatusUpdate.TrackingNumber, shipmentStatusUpdate.Status);

            try
            {
                await _shipmentsRepository.UpdateAsync(shipmentStatusUpdate);

                logger.LogInformation("Shipment {TrackingNumber} was updated to status {Status}", shipmentStatusUpdate.TrackingNumber, shipmentStatusUpdate.Status);

                return(new OkResult());
            }
            catch (ShipmentNotFoundException)
            {
                logger.LogInformation("Shipment {TrackingNumber} was not found");
                return(new NotFoundResult());
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Shipment_UpdateStatus([FromBody] ShipmentStatusUpdate shipmentStatusUpdate)
        {
            try
            {
                await _shipmentRepository.UpdateAsync(shipmentStatusUpdate);

                return(Ok());
            }
            catch (ShipmentNotFoundException)
            {
                return(NotFound());
            }
        }
Esempio n. 3
0
 public async Task UpdateAsync(ShipmentDTO item)
 {
     var mappedItem = _mapper.Map <Shipment>(item);
     await _repo.UpdateAsync(mappedItem);
 }