Esempio n. 1
0
        public Trip Convert(AddTripCommand addTripCommand)
        {
            var trip = _mapper.Map <Trip>(addTripCommand);

            trip.TripDestinations = addTripCommand.TripDestinations?.Select(x => _tripDestinationConverter.Convert(x)).ToList();
            return(trip);
        }
Esempio n. 2
0
        public IActionResult AddTrip([FromBody] TripDto tripDto)
        {
            EnsureArg.IsNotNull(tripDto);

            var command = new AddTripCommand(tripDto);

            CommandDispatcher.Execute(command);
            return(NoContent());
        }
 /// <summary>
 /// Returns TRUE if AddTripCommand is valid and average speed is between 5 mph and 100 mph. FALSE otherwise.
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 public static bool IsValid(this AddTripCommand cmd)
 {
     if (!string.IsNullOrEmpty(cmd.DriverName) && cmd.MilesDriven > 0 && cmd.StopTime > cmd.StartTime)
     {
         var speed = cmd.MilesDriven / (cmd.StopTime - cmd.StartTime).TotalHours;
         if (speed >= 5 && speed <= 100)
         {
             return(true);
         }
     }
     return(false);
 }