Example #1
0
        public IActionResult DeleteImage(int id)
        {
            try
            {
                _imageProvider.DeleteImage(id);
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new ErrorResponse(ex.Message)));
            }

            return(ListImageIndices());
        }
Example #2
0
        /// <summary>
        /// Saves the avatar image.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="file">The file.</param>
        /// <returns>Task{System.String}.</returns>
        public async Task <string> SaveAvatarImage(string userId, FileData file)
        {
            var result = await _imageProvider.SaveImage(file, BlobContainer.AvatarImages);

            if (String.IsNullOrEmpty(result))
            {
                var user = await _userRepository.GetUser(userId);

                if (String.IsNullOrEmpty(user.AvatarUrl))
                {
                    await _imageProvider.DeleteImage(user.AvatarUrl);
                }
            }
            return(result);
        }
Example #3
0
        public async Task DeleteImage(string imageId, string userId, bool deletedByModerator)
        {
            var image = await _unitOfWork.ImageRepository.Get(imageId);

            if (image == null)
            {
                throw new ObjectNotFoundException($"Image with id:{imageId} not found.");
            }
            if (image.UserId != userId && !deletedByModerator)
            {
                throw new ImageAccessException("This image cannot be accessed by this user.");
            }

            var imagePath = Path.Combine(_fileOptions.DirectoryPath, userId);

            _imageProvider.DeleteImage(imagePath, image);
            _unitOfWork.ImageRepository.Delete(image);
            await _unitOfWork.Commit();
        }
Example #4
0
 public Task Delete(string id)
 {
     return(_imageProvider.DeleteImage(id));
 }