Пример #1
0
        public ImageUrlDto UploadImage(FileDescription imageFile)
        {
            if (!imageFile.IsImageFile())
            {
                throw new BusinessException("Your Upload is not a Images!");
            }

            var fileName = ImageUrlHelper.NewImageFileName();

            _storageProvider.CreateImage(ImageUrlHelper.GetFileGuid(fileName).GetValueOrDefault(), imageFile.Data);

            return(ImageUrlHelper.ToImageUrl(fileName));
        }
Пример #2
0
        public async Task <ImageUrlDto> UpdateUserAvatarAsync(int userId, EditUserAvatarDto dto)
        {
            var userFromDb = await _userRepository.GetAsync(userId);

            if (dto.ImageFiles.IsNullOrEmpty())
            {
                userFromDb.ADUserAvatarFileName = string.Empty;
            }
            else
            {
                userFromDb.ADUserAvatarFileName = ImageUrlHelper.NewImageFileName();

                _storageProvider.CreateImage(ImageUrlHelper.GetFileGuid(userFromDb.ADUserAvatarFileName).GetValueOrDefault(), dto.ImageFiles.First());
            }

            await _userRepository.UpdateAsync(userFromDb);

            await _unitOfWork.CompleteAsync();

            return(ImageUrlHelper.ToImageUrl(ImageUrlHelper.GetFileGuid(userFromDb.ADUserAvatarFileName).GetValueOrDefault()));
        }