Exemplo n.º 1
0
        public ActionResult <IEnumerable <DtoDeparture> > SaveDeparture(DepartureModel departure)
        {
            DtoDeparture added = new DtoDeparture();

            if (ModelState.IsValid)
            {
                try
                {
                    added = _departureService.RegistryDeparture(DepartureMapper.convertModelToDTO(departure));
                }
                catch (Exception e)
                {
                    if (e is AppException)
                    {
                        return(UnprocessableEntity(e.Message));
                    }
                    else
                    {
                        return(BadRequest(e.Message));
                    }
                }
            }

            return(CreatedAtAction(nameof(GetDeparture), new { id = added.Id }, added));
        }
Exemplo n.º 2
0
        public static DtoDeparture convertModelToDTO(DepartureModel departureModel)
        {
            DtoDeparture dtoDeparture = new DtoDeparture();

            if (departureModel != null)
            {
                dtoDeparture.IdVehicle = departureModel.IdVehicle;
            }

            return(dtoDeparture);
        }
Exemplo n.º 3
0
 public static RuterModel FromApiModel(DepartureModel model)
 {
     return(new RuterModel
     {
         LastUpdated = model.RecordedAtTime,
         LineNumber = model.MonitoredVehicleJourney.PublishedLineName,
         Destination = model.MonitoredVehicleJourney.DestinationName,
         ExpectedArrivalDelay = (model.MonitoredVehicleJourney.MonitoredCall.ExpectedArrivalTime - model.MonitoredVehicleJourney.MonitoredCall.AimedArrivalTime).Minutes,
         ExpectedDepartureDelay = (model.MonitoredVehicleJourney.MonitoredCall.ExpectedDepartureTime - model.MonitoredVehicleJourney.MonitoredCall.AimedDepartureTime).Minutes,
         FromPlatform = model.MonitoredVehicleJourney.MonitoredCall.DeparturePlatformName
     });
 }
Exemplo n.º 4
0
        public IActionResult Post([FromBody] DepartureModel value)
        {
            var validationResult = _depatureModelValidator.Validate(value);

            if (!validationResult.IsValid)
            {
                throw new BadRequestException(validationResult.Errors);
            }

            var entity = _departureService.Create(value);

            return(Json(entity));
        }
Exemplo n.º 5
0
        public static DepartureModel convertDTOToModel(DtoDeparture dtoDeparture)
        {
            DepartureModel departureModel = new DepartureModel();

            if (dtoDeparture != null)
            {
                departureModel.IdVehicle      = dtoDeparture.IdVehicle;
                departureModel.Id             = dtoDeparture.Id;
                departureModel.DepartureTime  = dtoDeparture.DepartureTime;
                departureModel.RateTotalValue = dtoDeparture.RateValue;
                departureModel.EntryTime      = dtoDeparture.EntryTime;
                departureModel.Days           = dtoDeparture.Days;
                departureModel.Hours          = dtoDeparture.Hours;
            }

            return(departureModel);
        }