public void CreateParcel_Succeeded() { Parcel parcel = new Parcel(); int id = _dal.Create(parcel); Assert.AreNotEqual(0, id); }
public string AddParcel(IO.Swagger.Models.Parcel serviceParcel) { try { if (serviceParcel == null) { throw new BlException("Received Service Parcel was null"); } var blParcel = _mapper.Map <Entities.Parcel>(serviceParcel); if (blParcel != null) { string validationResults = ValidatePreAddedParcel(blParcel); if (validationResults != "") { _logger.LogError(validationResults); throw new BlException("Given parcel is not valid", new ArgumentException("Given Parcel is not valid")); } } var dalParcel = _mapper.Map <DataAccess.Entities.Parcel>(blParcel); dalParcel.TrackingInformation = GenerateTrackingInformation(dalParcel); dalParcel.TrackingNumber = GenerateTrackingNumber(8); _parcelRepo.Create(dalParcel); return(dalParcel.TrackingNumber); } catch (Exception ex) { _logger.LogError("Could not add parcel", ex); throw new BlException("Could not add parcel", ex); } }
public bool AddParcel(ParcelModel parcel) { try { ValidateParcel(parcel); var parcelModel = Mapper.Map <ParcelModel, ParcelDTO>(parcel); _parcelRepository.Create(parcelModel); _logger.Info("ParcelModel saved to Repo"); return(true); } catch (Exception ex) { throw new BLException("BL error adding parcel: " + ex.Message, ex); } }
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); } }
public string TransferParcel(string parcelID, Parcel parcel) { string senderGeoString = parcel.Sender.ToGeoCodingString(); string recipientGeoString = parcel.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($"Submiting parcel {parcelID}"); parcel.Submit(parcelID); logger.LogDebug($"calculating route betweend sender {senderHop.Code} and recipeint {recipientHop.Code}"); List <HopArrival> route = routeCalculator.CalculateRoute(warehouse, senderHop.Code, recipientHop.Code, parcel.EntryDate); logger.LogDebug($"validating parcel ({parcelID})"); ParcelValidator validator = new ParcelValidator(); ValidationResult result = validator.Validate(parcel); if (result.IsValid) { logger.LogDebug($"Parcel ({parcelID}) was valid"); Data.Parcel dataParcel = this.mapper.Map <Data.Parcel>(parcel); logger.LogInformation("Creating Parcel DB entry"); try { parcelRepository.Create(dataParcel); return(parcelID); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } } else { InvalidParcelException e = new InvalidParcelException(string.Join("", result.Errors)); logger.LogError(e, $"Parcel ({parcelID}) was invalid"); throw e; } }