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)); }
public static DtoDeparture convertModelToDTO(DepartureModel departureModel) { DtoDeparture dtoDeparture = new DtoDeparture(); if (departureModel != null) { dtoDeparture.IdVehicle = departureModel.IdVehicle; } return(dtoDeparture); }
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 }); }
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)); }
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); }