public void ReportParcelDelivery(string parcelID) { Data.Parcel dataParcel; try { logger.LogDebug($"getting parcel {parcelID} from repo"); dataParcel = parcelRepository.GetByTrackingId(parcelID); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } Parcel businessParcel = this.mapper.Map <Parcel>(dataParcel); businessParcel.ReportDelivery(); Data.Parcel mappedParcel = this.mapper.Map <Data.Parcel>(businessParcel); try { logger.LogInformation($"updating parcel {parcelID}"); parcelRepository.Delivered(mappedParcel); List <Data.Webhook> dataWebhooks = webhookRepository.GetByTrackingId(parcelID); List <Webhook> webhooks = new List <Webhook>(); dataWebhooks.ForEach(hook => webhooks.Add(this.mapper.Map <Webhook>(hook))); NotifyAllSubscribers(webhooks); DeleteAllSubscribers(webhooks); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } }
public void SubscribeToParcel(string trackingId, string url) { try { logger.LogDebug($"Checking if Parcel with trackingId {trackingId} exists"); parcelRepository.GetByTrackingId(trackingId); // if it doesnt throw an error it found a parcel DateTime currentTime = DateTime.Now; Data.Webhook webhook = new Data.Webhook() { TrackingId = trackingId, Url = url, CreatedAt = currentTime }; logger.LogDebug($"Creating entry for webhook with trackingId: {trackingId}, url: {url}, createdAt: {currentTime}"); webhookRepository.Create(webhook); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } }
public Parcel TrackParcel(string trackingId) { try { logger.LogInformation($"getting parcel {trackingId} from repo"); Data.Parcel dataParcel = parcelRepository.GetByTrackingId(trackingId); Parcel businessParcel = this.mapper.Map <Parcel>(dataParcel); string senderGeoString = businessParcel.Sender.ToGeoCodingString(); string recipientGeoString = businessParcel.Recipient.ToGeoCodingString(); logger.LogDebug($"converting sender geoCodingString '{senderGeoString}' to Location"); logger.LogDebug($"converting recepient geoCodingString '{recipientGeoString}' to Location"); Geocoding.Location senderAddress = geoCodingAgent.EncodeAddress(senderGeoString); Geocoding.Location recipientAddress = geoCodingAgent.EncodeAddress(recipientGeoString); Data.Hop dataSenderHop; Data.Hop dataRecipientHop; try { dataSenderHop = hopRepository.GetByCoordinates(senderAddress.Latitude, senderAddress.Longitude); dataRecipientHop = hopRepository.GetByCoordinates(recipientAddress.Latitude, recipientAddress.Longitude); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } Data.Warehouse dataWarehouse; try { logger.LogDebug("load full warehouse hierarchy"); dataWarehouse = wareHouseRepository.Read(); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } Hop senderHop = this.mapper.Map <Hop>(dataSenderHop); Hop recipientHop = this.mapper.Map <Hop>(dataRecipientHop); Warehouse warehouse = this.mapper.Map <Warehouse>(dataWarehouse); logger.LogDebug($"calculating route between sender {senderHop.Code} and recipeint {recipientHop.Code}"); List <HopArrival> route = routeCalculator.CalculateRoute(warehouse, senderHop.Code, recipientHop.Code, businessParcel.EntryDate); //route Datetime now List <HopArrival> soonHop = new List <HopArrival>(); List <HopArrival> pastHop = new List <HopArrival>(); foreach (HopArrival ha in route) { if (ha.DateTime < DateTime.Now) { pastHop.Add(ha); } else { soonHop.Add(ha); } } businessParcel.VisitedHops = pastHop; businessParcel.FutureHops = soonHop; return(businessParcel); } catch (DataAccessLayerException e) { throw new BusinessLayerException(); } }