Example #1
0
        public MutationResult AddService(AddServiceToStationDto dto)
        {
            var station = Data.Stations.FirstOrDefault(x => x.Id == dto.StationId);

            if (station is null)
            {
                return new MutationResult
                       {
                           Error = "No such station"
                       }
            }
            ;

            var platform = station.Platforms.FirstOrDefault(x => x.Number == dto.PlatformNo);

            if (platform is null)
            {
                return new MutationResult
                       {
                           Error = "No such platform"
                       }
            }
            ;

            platform.Service = dto.Service;

            return(new MutationResult());
        }
    }
}
        public IActionResult AddService([FromRoute] string stationId, [FromBody] AddServiceToStationDto dto)
        {
            var station = Data.Stations.FirstOrDefault(x => x.Id == stationId);

            if (station is null)
            {
                return(BadRequest(new
                {
                    Error = "Station does not exist"
                }));
            }

            var platform = station.Platforms.FirstOrDefault(x => x.Number == dto.Platform);

            if (platform is null)
            {
                return(NotFound(new
                {
                    Error = "Platform does not exist"
                }));
            }

            platform.Service = dto.Service;

            return(Ok());
        }