public async Task <TripDTO> PartialUpdateTrip(int tripId, JsonPatchDocument <TripDTO> patchDoc) { var trip = await _tripRepo.GetTripById(tripId); if (trip == null) { return(null); } TripDTO updatedTrip = TripMapper.ConvertEntityToModel(trip); patchDoc.ApplyTo(updatedTrip); trip = TripMapper.UpdateEntityFromModel(trip, updatedTrip); if (trip != null && await _tripRepo.UpdateTrip(trip)) { return(TripMapper.ConvertEntityToModel(trip)); } return(null); }
public async Task <TripDTO> UpdateTrip(int tripId, TripDTO tripModel) { var trip = await _tripRepo.GetTripById(tripId); //upsert if (trip == null) { trip = new Trip() { Id = tripId }; } trip = TripMapper.UpdateEntityFromModel(trip, tripModel); if (trip != null && await _tripRepo.UpdateTrip(trip)) { return(TripMapper.ConvertEntityToModel(trip)); } return(null); }