public IList <TruckModel> GetAllTrucks() { try { List <TruckDTO> truckDAOs = _truckRepository.GetAll().ToList(); var truckModels = Mapper.Map <List <TruckDTO>, List <TruckModel> >(truckDAOs); return(truckModels); } catch (Exception ex) { throw new BLException("Error getting trucks", ex); } }
private DataAccess.Entities.Truck SelectNearestTruck(Entities.Location blLocation) { var trucks = _truckRepo.GetAll(); var nearestTruck = trucks.FirstOrDefault(); var smallestDistance = DistanceCalculator.GetDistanceBetweenTwoPoints((double)nearestTruck.Latitude, (double)nearestTruck.Longitude, blLocation.Lat, blLocation.Lng); foreach (var truck in trucks) { var distance = DistanceCalculator.GetDistanceBetweenTwoPoints((double)truck.Latitude, (double)truck.Longitude, blLocation.Lat, blLocation.Lng); if (distance < smallestDistance) { smallestDistance = distance; nearestTruck = truck; } } return((decimal)smallestDistance <= nearestTruck.Radius ? nearestTruck : null); }
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); } }
public async Task <IList <Truck> > GetAllTruck( [FromServices] ITruckRepository repository) { return(await repository.GetAll()); }