public async Task DeleteAccommodationPicture(int pictureId)
        {
            using (_unitOfWork)
            {
                AccommodationPicture accommodationPicture = await _unitOfWork.AccommodationPictureRepository.FindByID(pictureId);

                Accommodation accommodation = await _unitOfWork.AccommodationRepository.GetAccommodationWithLocation(accommodationPicture.AccommodationId);

                AccommodationPictureDTO deleteInfo = _mapper.Map <AccommodationPicture, AccommodationPictureDTO>(accommodationPicture);
                deleteInfo.Picture = "";
                _unitOfWork.AccommodationPictureRepository.Delete(pictureId);
                await _unitOfWork.Save();

                await _messageControllerService.NotifyOnTripChanges(accommodation.Location.TripId, "RemoveAccommodationPicture", deleteInfo);
            }
        }
        public async Task <ActionResult> AddAccommodationPicture(int tripId, [FromBody] AccommodationPictureCreateDTO picture)
        {
            try
            {
                if (!await _editRightsService.HasEditRights(tripId))
                {
                    return(BadRequest(new JsonResult("You can't currently edit this trip.")));
                }
                AccommodationPictureDTO accommodationPicture = await _accommodationService.AddAccommodationPicture(picture);

                await _editRightsService.ProlongEditRights(tripId, _redisAppSettings.EditRightsProlongedTTL);

                return(Ok(accommodationPicture));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        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);
            }
        }