Пример #1
0
        public async Task <TripDTO> CreateTrip(TripDTO tripModel)
        {
            Trip trip = TripMapper.ConvertModelToEntity(tripModel);

            if (await _tripRepo.CreateTrip(trip))
            {
                return(TripMapper.ConvertEntityToModel(trip));
            }

            return(null);
        }
Пример #2
0
        public async Task <TripDTO> GetTrip(int tripId)
        {
            var trip = await _tripRepo.GetTripById(tripId);


            if (trip != null)
            {
                return(TripMapper.ConvertEntityToModel(trip));
            }

            return(null);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }