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 GetParcel_ByTrackingId_Succeeded() { string given = "XXXX1"; Receipient customer = new Receipient() { Name = "Johannes", Street = "Street", PostalCode = "A-1230" }; Parcel parcel = new Parcel() { TrackingId = given, Receipient = customer, Sender = customer }; _dal.Create(parcel); parcel = _dal.GetByTrackingID(given); Assert.NotNull(parcel); Assert.AreEqual(parcel.TrackingId, given); }
public Parcel TrackPackage(string trackingId) { try { DAL.Parcel p = _sqlRepo.GetByTrackingID(trackingId); return(_mapper.Map <Parcel>(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 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 DTO.NewParcelInfo SubmitParcelIntoBL(Parcel parcel) { try { var validator = new ParcelValidation(); var checkParcel = validator.Validate(parcel); if (!checkParcel.IsValid) { throw new BLException("BL: Parcel Validation failed"); } //check if parcel.trackingId is set -> only happens if it is from a Logistic Partner if (parcel.TrackingId == null || _sqlRepoParcel.GetByTrackingID(parcel.TrackingId) != null) { //generate new trackingId until it is a unique do { parcel.TrackingId = GenerateTrackingId(); } while (_sqlRepoParcel.GetByTrackingID(parcel.TrackingId) != null); } //Set State to InTransport parcel.State = Parcel.StateEnum.InTransportEnum; //Encode Sender and Receipient into a Location Location recLocation = _agent.EncodeGeocodeAsync(GenerateAddress(parcel.Receipient)); Location sendLocation = _agent.EncodeGeocodeAsync(GenerateAddress(parcel.Sender)); //Find responsible Truck for Sender - START //currently only for austria -> NO Transferwarehouse var senderTruck = _mapper.Map <Truck>(_sqlRepoHop.GetTruckByLocation(sendLocation)); HopArrival firstHop = new HopArrival() { Code = senderTruck.Code, DateTime = DateTime.Now }; parcel.VisitedHops.Add(firstHop); //Find responsible Truck for Recipient - FINISH var recTruck = _mapper.Map <Truck>(_sqlRepoHop.GetTruckByLocation(recLocation)); //Calculate Route var rcptHopList = GetRouteToRoot(recTruck); var senderHopList = GetRouteToRoot(senderTruck); //var intersect = rcptHopList.Intersect(senderHopList,EqualityComparerFactory.Create<WarehouseNextHops>((a) => a.HopACode.GetHashCode(), (a, b) =)) bool found = false; Hop intersection = null; foreach (var senderStep in senderHopList) { if (found == false) { foreach (var step in rcptHopList) { if (senderStep.Code == step.Code) { intersection = senderStep; found = true; break; } } } } //Get path to intersection var rcptJourney = rcptHopList.TakeWhile(p => p.Code != intersection.Code).ToList(); var senderJourney = senderHopList.TakeWhile(p => p.Code != intersection.Code).ToList(); senderJourney.Add(intersection); //reverse rcptJourney rcptJourney.Reverse(); senderJourney.AddRange(rcptJourney); senderJourney.Add(recTruck); foreach (var step in senderJourney) { HopArrival futureHop = new HopArrival() { Code = step.Code, DateTime = DateTime.Now }; parcel.FutureHops.Add(futureHop); } var parcelDAL = _mapper.Map <DAL.Parcel>(parcel); _sqlRepoParcel.Create(parcelDAL); var NPInfoMapped = _mapper.Map <DTO.NewParcelInfo>(parcel); DTO.NewParcelInfo NPInfo = (DTO.NewParcelInfo)NPInfoMapped; return(NPInfo); } 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); } }