public async Task <AccommodationPictureDTO> AddAccommodationPicture(AccommodationPictureCreateDTO picture) { using (_unitOfWork) { Accommodation accommodation = await _unitOfWork.AccommodationRepository.GetAccommodationWithLocation(picture.AccommodationId); AccommodationPicture accommodationPicture = new AccommodationPicture { AccommodationPictureId = 0, AccommodationId = accommodation.AccommodationId, Accommodation = accommodation, Picture = "temp", }; await _unitOfWork.AccommodationPictureRepository.Create(accommodationPicture); await _unitOfWork.Save(); accommodationPicture.Picture = PictureManagerService.SaveImageToFile(picture.Picture, accommodation.GetType().Name, accommodationPicture.AccommodationPictureId); accommodationPicture.Accommodation = accommodation; if (accommodation.Pictures == null) { accommodation.Pictures = new List <AccommodationPicture>(); } accommodation.Pictures.Add(accommodationPicture); _unitOfWork.AccommodationPictureRepository.Update(accommodationPicture); await _unitOfWork.Save(); accommodationPicture.Picture = null; AccommodationPictureDTO res = _mapper.Map <AccommodationPicture, AccommodationPictureDTO>(accommodationPicture); res.Picture = picture.Picture; await _messageControllerService.NotifyOnTripChanges(accommodation.Location.TripId, "AddAccommodationPicture", res); return(res); } }