Esempio n. 1
0
        public async Task DeletePhoto(int userId, int photoId)
        {
            var user = await _usersService.GetUser(userId, true);

            if (!user.Photos.Any(p => p.Id == photoId))
            {
                throw new NotFoundException();
            }

            var photo = await this.GetPhoto(photoId);

            if (photo.IsMain)
            {
                throw new BadRequestException("You cannot delete your main photo.");
            }

            if (!string.IsNullOrWhiteSpace(photo.PublicId))
            {
                await _imageUploader.DeleteAsync(photo.PublicId);
            }

            _unitOfWork.Photos.Remove(photo);

            await _unitOfWork.CommitAsync();
        }
Esempio n. 2
0
        public async Task TestImageUploader()
        {
            var url = await imageUploader.UploadAsync("test.txt", new byte[] { 48, 49, 50 });

            var urls = await imageUploader.ListAsync();

            if (!urls.Contains(url))
            {
                throw new Exception("Cannot see uploaded file!");
            }
            await imageUploader.DeleteAsync("test.txt");
        }