Esempio n. 1
0
        public async Task <PhotoForDetailedDto> Upload(PhotoForCreationDto photoForCreation)
        {
            var uploadResult = _cloudUploadService.UploadPhotoToCloud(photoForCreation.File);

            var photo = _mapper.Map <Domain.Entities.Photo>(photoForCreation);

            photo.Url      = uploadResult.Url;
            photo.PublicId = uploadResult.PublicId;

            var mainPhotoSpecification = new PhotoFilterSpecification(photoForCreation.EntityTypeId, photoForCreation.EntityId, isMain: true);
            var mainPhoto = await _uow.Repository <Domain.Entities.Photo>().FindOneAsync(mainPhotoSpecification);

            if (mainPhoto == null)
            {
                photo.IsMain = true;
            }

            _uow.Repository <Domain.Entities.Photo>().Add(photo);

            await _uow.SaveAsync();

            var photoToReturn = _mapper.Map <PhotoForDetailedDto>(photo);

            return(photoToReturn);
        }
Esempio n. 2
0
        public async Task IncludeMainPhoto(IMainPhotoUploadable entity, int entityTypeId)
        {
            var photoSpecification = new PhotoFilterSpecification(entityTypeId, entity.Id, isMain: true);

            var photo = await _uow.Repository <Domain.Entities.Photo>().FindOneAsync(photoSpecification);

            entity.MainPhoto = _mapper.Map <PhotoForDetailedDto>(photo);
        }
Esempio n. 3
0
        public async Task <IEnumerable <PhotoForDetailedDto> > GetEntityPhotos(int entityTypeId, int entityId)
        {
            var photoSpecification = new PhotoFilterSpecification(entityTypeId, entityId);

            var photos = await _uow.Repository <Domain.Entities.Photo>().FindAsync(photoSpecification);

            var result = _mapper.Map <IEnumerable <PhotoForDetailedDto> >(photos);

            return(result);
        }
Esempio n. 4
0
        public async Task SetMain(int photoId)
        {
            var photo = await _uow.Repository <Domain.Entities.Photo>().FindByIdAsync(photoId);

            var photoSpecification = new PhotoFilterSpecification(photo.EntityTypeId, photo.EntityId);

            var userPhotos = await _uow.Repository <Domain.Entities.Photo>().FindAsync(photoSpecification);

            var mainPhoto = userPhotos.FirstOrDefault(x => x.IsMain);

            mainPhoto.IsMain = false;

            photo.IsMain = true;

            await _uow.SaveAsync();
        }
Esempio n. 5
0
        public async Task <IEnumerable <Photo> > ListAsync(long propertyId)
        {
            var spec = new PhotoFilterSpecification(propertyId);

            return(await _photoRepository.ListAsync(spec));
        }