예제 #1
0
        public async Task <Station> UpdateStation(int stationId, NewStationDto station)
        {
            var stationForUpdate = await _stationRepository.GetStation(stationId);

            _mapper.Map(station, stationForUpdate);

            stationForUpdate.StationLines = null;

            if (await SaveAll())
            {
                stationForUpdate = await _stationRepository.GetStation(stationId);

                if (stationForUpdate.StationLines == null)
                {
                    foreach (var lines in station.Lines)
                    {
                        await AddLineToStation(stationForUpdate.Id, lines.Id);
                    }
                }
                return(stationForUpdate);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        public async Task <IActionResult> AddStation(NewStationDto station)
        {
            Station newStation = new Station();

            _mapper.Map(station, newStation);

            var result = await _publicTransportRepository.AddStation(newStation);

            if (result != null)
            {
                if (station.Lines != null)
                {
                    foreach (var line in station.Lines)
                    {
                        await _publicTransportRepository.AddLineToStation(result.Id, line.Id);
                    }
                }

                return(Ok(result));
            }
            else
            {
                return(BadRequest("Failed while creating new station"));
            }
        }
예제 #3
0
        public async Task <IActionResult> UpdateStation(int stationId, NewStationDto station)
        {
            var result = await _publicTransportRepository.UpdateStation(stationId, station);

            if (result != null)
            {
                if (station.Lines != null)
                {
                    foreach (var line in station.Lines)
                    {
                        await _publicTransportRepository.AddLineToStation(result.Id, line.Id);
                    }
                }
                return(Ok(result));
            }
            else
            {
                return(BadRequest("Failed to update station"));
            }
        }