public ActionResult <Truck> PostTruck(TruckCreateDto truckCreateDto) { var truckModel = _mapper.Map <Truck>(truckCreateDto); _repository.PostTruck(truckModel); _repository.SaveChanges(); var truckReadDto = _mapper.Map <TruckReadDto>(truckModel); return(CreatedAtRoute(nameof(GetTruckById), new { Id = truckReadDto.TruckId }, truckReadDto)); }
public ActionResult <Truck> PostTruckForSP(int SPId, TruckCreateDto truckCreateDto) { var truckModel = _mapper.Map <Truck>(truckCreateDto); var SPModel = _repository.GetServiceProviderById(SPId); if (SPModel == null) { return(NotFound("SPID is " + SPId)); } truckModel.ServiceProvider = SPModel; _repository.PostTruck(truckModel); _repository.SaveChanges(); var truckReadDto = _mapper.Map <TruckReadDto>(truckModel); return(CreatedAtRoute(nameof(TrucksController.GetTruckById), new { Id = truckReadDto.TruckId }, truckReadDto)); }