コード例 #1
0
 public IActionResult Put(int busStopId, [FromBody] UpdateBusStopDto updateBusStopDto)
 {
     try
     {
         var updateBusStop = this._Mapper.Map <UpdateBusStopDto, BusStop>(updateBusStopDto);
         updateBusStop.ID = busStopId;
         if (this._BusStopRepository.SaveBusStop(updateBusStop) > 0)
         {
             return(Ok(
                        this._Mapper.Map <BusStop, ReturnBusStopDto>(updateBusStop)
                        ));
         }
         return(BadRequest(new BadRequestMessage
         {
             Message = new string[] {
                 "Bus stop fails to update.",
                 "Tip: ID does not exist",
                 "StopNumber is already exists."
             }
         }));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Internal server error"));
     }
 }
コード例 #2
0
        public void UpdateBusStop()
        {
            var target = new BusStopsController(this._EFRouteBusRepository, this._EFBusStopRepository, this._MockMapper);

            var newBusStop = new UpdateBusStopDto
            {
                StopNumber = "UTest-001",
                Label      = "Update-Test Bus Stop",
                Longitude  = 1.0,
                Latitude   = 2.0,
                Zone       = 2
            };

            var okResult = target.Put(93, newBusStop) as OkObjectResult;
            var busStop  = (ReturnBusStopDto)okResult.Value;

            Assert.Equal(200, okResult.StatusCode);
            Assert.Equal("UTest-001", busStop.StopNumber.ToString());
            Assert.Equal(1.0, busStop.Longitude);
        }