public async Task UpdateAsync(BusStationEntity busStation) { Guard.ArgumentNotNull(busStation, nameof(busStation)); var busRoutes = await _repository.GetById(busStation.Id).ConfigureAwait(false); if (busRoutes != null) { await _repository.Update(busStation).ConfigureAwait(false); } }
public async Task Update(BusStationEntity entity) { await _busStaions.FindOneAndReplaceAsync(x => x.Id == entity.Id, entity).ConfigureAwait(false); }
public async Task Add(BusStationEntity entity) { await _busStaions.InsertOneAsync(entity).ConfigureAwait(false); }
public async Task <IActionResult> GetRout([FromRoute] string startcoordonates, [FromRoute] string endcoordonates, [FromRoute] string cityname) { if (startcoordonates == string.Empty || startcoordonates == null || endcoordonates == string.Empty || endcoordonates == null || cityname == string.Empty || cityname == null) { return(BadRequest()); } var res = await _cityService.GetByNameAsync(cityname).ConfigureAwait(false); if (res == null) { return(BadRequest()); } HashSet <BusStationEntity> stationEntities = new HashSet <BusStationEntity>(); foreach (BusRouteEntity bus in res.BusRoutes) { stationEntities.UnionWith(bus.BusStations); } // Fac cast la coordonatele din input CoordinatesEntity coordinatesEntity = new CoordinatesEntity(Convert.ToDouble(startcoordonates.Split('_')[0]), Convert.ToDouble(startcoordonates.Split('_')[1])); CoordinatesEntity coordinatesEntity1 = new CoordinatesEntity(Convert.ToDouble(endcoordonates.Split('_')[0]), Convert.ToDouble(endcoordonates.Split('_')[1])); // Caut cea mai apropiata statie pentru punctul de start double longDiff = 300.0; double latDiff = 300.0; BusStationEntity station = new BusStationEntity(); // Caut cea mai apropiata statie pentru punctul de stop double longDiff1 = 300.0; double latDiff1 = 300.0; BusStationEntity stationEntity = new BusStationEntity(); foreach (BusStationEntity bus in stationEntities) { // Caut cea mai apropiata statie pentru punctul de start if (Math.Abs(bus.Coordinates.Latitude - coordinatesEntity.Latitude) <= latDiff && Math.Abs(bus.Coordinates.Longitude - coordinatesEntity.Longitude) <= longDiff) { station = new BusStationEntity { Id = bus.Id, Name = bus.Name, Coordinates = bus.Coordinates, Buses = bus.Buses, CreationDate = bus.CreationDate, ModifiedDate = bus.ModifiedDate }; longDiff = Math.Abs(bus.Coordinates.Latitude - coordinatesEntity.Latitude); latDiff = Math.Abs(bus.Coordinates.Longitude - coordinatesEntity.Longitude); } // Caut cea mai apropiata statie pentru punctul de stop if (Math.Abs(bus.Coordinates.Latitude - coordinatesEntity1.Latitude) <= latDiff1 && Math.Abs(bus.Coordinates.Longitude - coordinatesEntity1.Longitude) <= longDiff1) { stationEntity = new BusStationEntity { Id = bus.Id, Name = bus.Name, Coordinates = bus.Coordinates, Buses = bus.Buses, CreationDate = bus.CreationDate, ModifiedDate = bus.ModifiedDate }; longDiff1 = Math.Abs(bus.Coordinates.Latitude - coordinatesEntity1.Latitude); latDiff1 = Math.Abs(bus.Coordinates.Longitude - coordinatesEntity1.Longitude); } } string startStationName = station.Name; string stopStationName = stationEntity.Name; List <(string, string, CoordinatesEntity, string, CoordinatesEntity)> realResult = BusStationExtensions.ShortestPath(new List <BusRouteEntity>(res.BusRoutes), startStationName, stopStationName); List <BktModel> bktResult = new List <BktModel>(); if (realResult == null) { return(NotFound()); } foreach ((string, string, CoordinatesEntity, string, CoordinatesEntity)iterator in realResult) { BktModel bktModel = new BktModel { RouteNumber = iterator.Item1, BoardingStation = iterator.Item2, BoardingCoodinates = iterator.Item3, ExitStation = iterator.Item4, ExitCoordinates = iterator.Item5 }; bktResult.Add(bktModel); } if (realResult == null) { return(NotFound()); } else { return(Ok(bktResult)); } }
public async Task AddAsync(BusStationEntity entity) { Guard.ArgumentNotNull(entity, nameof(entity)); await _repository.Add(entity).ConfigureAwait(false); }