public IO.Swagger.Models.TrackingInformation TrackParcel(string trackingNumber) { try { var dalParcel = _parcelRepo.GetByTrackingNumber(trackingNumber); if (dalParcel == null) { throw new BlException("Parcel not found in Database"); } var hopArr = _hopRepo.GetByTrackingInformationId(dalParcel.TrackingInformationId); foreach (var h in hopArr) { if (h.Status == "visited") { dalParcel.TrackingInformation.VisitedHops.Add(h); } else if (h.Status == "future") { dalParcel.TrackingInformation.FutureHops.Add(h); } } var blParcel = _mapper.Map <Parcel>(dalParcel); if (blParcel != null) { _logger.LogError(ValidateParcel(blParcel)); } var info = _mapper.Map <IO.Swagger.Models.TrackingInformation>(blParcel.TrackingInformation); return(info); } catch (Exception ex) { _logger.LogError("Could not find parcel", ex); throw new BlException("Could not find parcel", ex); } }
public void ScanParcel(string trackingNumber, string code) { try { var dalParcel = _parcelRepo.GetByTrackingNumber(trackingNumber); if (dalParcel == null) { throw new BlException("Parcel not found in Database"); } var dalInfo = _trackingRepo.GetById(dalParcel.TrackingInformationId); var hopArr = _hopArrivalRepo.GetByTrackingInformationId(dalInfo.Id); int index = hopArr.FindIndex(a => a.Code == code); if (index == -1) { throw new BlException("Wrong hop for parcel"); } hopArr[index].Status = "visited"; hopArr[index].DateTime = DateTime.Now; var trucks = _truckRepository.GetAll(); foreach (var t in trucks) { if (t.Code == hopArr[index].Code) { dalInfo.State = DataAccess.Entities.TrackingInformation.StateEnum.InTruckDeliveryEnum; break; } } _hopArrivalRepo.Update(hopArr[index]); } catch (Exception ex) { _logger.LogError("Could not update parcel information", ex); throw new BlException("Could not update parcel information", ex); } }