예제 #1
0
 public static Stop ToStop(this CreatedStop stop)
 {
     if (stop != null)
     {
         return(new Stop
         {
             CityId = stop.CityId,
             Name = stop.Name,
             Duration = stop.Duration,
             ArrivalTime = stop.ArrivalTime,
             DepartureTime = stop.DepartureTime
         });
     }
     else
     {
         return(null);
     }
 }
예제 #2
0
        public IActionResult AddStop(CreatedStop createdStop)
        {
            if (createdStop.DepartureTime > createdStop.ArrivalTime)
            {
                return(BadRequest());
            }
            TimeSpan duration = createdStop.ArrivalTime - createdStop.DepartureTime;

            createdStop.Duration = duration.TotalSeconds;
            int  idOfNewElement = _stops.AddStop(createdStop);
            Stop stop           = createdStop.ToStop();

            stop.StopId = idOfNewElement;

            stop.Duration = duration.TotalSeconds;

            return(Created(HttpContext.Request.Scheme + "//" + HttpContext.Request.Host + HttpContext.Request.Path + "/" + idOfNewElement, stop));
        }
예제 #3
0
        public int AddStop(CreatedStop createdStop)
        {
            Stop stop = createdStop.ToStop();

            return(_stopRepository.Insert(stop.ToEntity()));
        }