public void UpdateParcel_Succeeded() { Receipient customer = new Receipient() { Name = "Johannes", Street = "Street", PostalCode = "A-1230" }; Parcel parcel = new Parcel() { State = Parcel.StateEnum.DeliveredEnum, Receipient = customer, Sender = customer }; int id = _dal.Create(parcel); Assert.AreNotEqual(0, id); //Assert.AreNotEqual(parcel.State, Parcel.StateEnum.InTransportEnum); parcel.State = Parcel.StateEnum.InTransportEnum; _dal.Update(parcel); parcel = _dal.GetByID(id); Assert.AreEqual(parcel.State, Parcel.StateEnum.InTransportEnum); }
public bool ReportDeliveryFinal(string trackingId) { try { var parcelDal = _sqlRepoParcel.GetByTrackingID(trackingId); if (parcelDal == null || parcelDal.FutureHops.Count != 1) { return(false); } var parcelBL = _mapper.Map <Parcel>(parcelDal); var validator = new ParcelValidation(); var checkParcel = validator.Validate(parcelBL); if (!checkParcel.IsValid) { return(false); } parcelDal.FutureHops.RemoveAt(0); parcelDal.State = DAL.Parcel.StateEnum.DeliveredEnum; _sqlRepoParcel.Update(parcelDal); //contact Webhook Subscriber //Find Webhook IDs with the same trackingID List <DAL.Webhook> deleteList = _webrep.GetWebhooksByTrackingID(trackingId); foreach (var hook in deleteList) { _webrep.Delete(hook.Id); } return(true); } catch (DAL.DALException exc) { _logger.LogError(exc.ToString()); throw new BLException($"{exc.GetType()} Exception in {System.Reflection.MethodBase.GetCurrentMethod().Name}", exc); } catch (Exception exc) { _logger.LogError(exc.ToString()); throw new BLException($"{exc.GetType()} Exception in {System.Reflection.MethodBase.GetCurrentMethod().Name}", exc); } }
public void TransferParcelPartner(string newtrackingId, string oldtrackingId) { try { DAL.Parcel p = _sqlRepo.GetByTrackingID(newtrackingId); p.OldTrackingId = oldtrackingId; _sqlRepo.Update(p); } catch (DAL.DALException exc) { _logger.LogError(exc.ToString()); throw new BLException($"{exc.GetType()} Exception in {System.Reflection.MethodBase.GetCurrentMethod().Name}", exc); } catch (Exception exc) { _logger.LogError(exc.ToString()); throw new BLException($"{exc.GetType()} Exception in {System.Reflection.MethodBase.GetCurrentMethod().Name}", exc); } }
public void ReportParcelHop(string parcelID, string code) { Data.Parcel dataParcel; try { logger.LogDebug($"getting parcel {parcelID} from repo"); dataParcel = parcelRepository.GetByTrackingId(parcelID); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } Data.Hop dataHop; try { logger.LogDebug($"getting hop {code} from repo"); dataHop = hopRepository.GetByCode(code); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } Parcel businessParcel = this.mapper.Map <Parcel>(dataParcel); Hop businessHop = this.mapper.Map <Hop>(dataHop); businessParcel.ReportHop(businessHop); if (code == businessParcel.FutureHops[0].Hop.Code) { businessParcel.VisitedHops.Add(businessParcel.FutureHops[0]); businessParcel.FutureHops.Remove(businessParcel.FutureHops[0]); } /* * if (code == businessParcel.FutureHops[0].Code) * { * switch (businessHop.) * { * case "Warehouse": * businessParcel.State = BL.Entities.Parcel.StateEnum.InTransportEnum; * * break; * case "Truck": * businessParcel.State = BL.Entities.Parcel.StateEnum.InTruckDeliveryEnum; * * break; * case "Transferwarehouse": * TransferToWarehouse(businessParcel, hop); * businessParcel.State = BL.Entities.Parcel.StateEnum.TransferredEnum; * * break; * default: * break; * } * * * webHookAgent.NotifyStateChanged(dalParcel); * * businessParcel.VisitedHops.Add(dalParcel.FutureHops[0]); * businessParcel.FutureHops.Remove(dalParcel.FutureHops[0]); * * parcelRepository.Update(dalParcel); * * } */ 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); } if (dataSenderHop == null || dataRecipientHop == null) { string errorMessage = "Error"; NoHopException e = new NoHopException(errorMessage); logger.LogError(e, $"No Hop found"); throw 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 betweend sender {senderHop.Code} and recipeint {recipientHop.Code}"); List <HopArrival> route = routeCalculator.CalculateRoute(warehouse, senderHop.Code, recipientHop.Code, businessParcel.EntryDate); bool checkIfOnRoute = false; foreach (HopArrival ha in route) { if (ha.Hop.Code == businessHop.Code) { checkIfOnRoute = true; break; } } if (!checkIfOnRoute) { throw new BusinessLayerException("Hop is not on TravelRoute"); } try { logger.LogInformation($"updating parcel {parcelID}"); parcelRepository.Update(this.mapper.Map <Data.Parcel>(businessParcel)); 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); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } }