Ejemplo n.º 1
0
        public async Task <LoadImageResult> LoadImageForCurrentUserAsync(IIdentity identity)
        {
            var userRepository = _unitOfWork.UserRepository;
            var currentUser    = await userRepository.GetSingleOrDefaultAsync(u => u.Username == identity.Name, u => u.ProfileImage);

            var imageExternalId = "default-profile-image";

            if (currentUser.ProfileImageId.HasValue)
            {
                imageExternalId = currentUser.ProfileImage.ExternalId;
            }

            var imagesRepository = _unitOfWork.GetRepository <UploadedImage>();
            var imageDetails     = await imagesRepository.GetSingleOrDefaultAsync(i => i.ExternalId == imageExternalId);

            if (imageDetails == null)
            {
                return(LoadImageResult.CreateUnsuccessful(LoadImageError.IncorrectExternalId));
            }

            var relativePath  = Path.Combine(_configuration.ImagesDirectory, imageDetails.FilePath);
            var fullPath      = Path.GetFullPath(relativePath);
            var isImageExists = File.Exists(fullPath);

            return(isImageExists
                ? LoadImageResult.CreateSuccessful(fullPath, imageDetails.MediaType)
                : LoadImageResult.CreateUnsuccessful(LoadImageError.ImageNotExists));
        }
Ejemplo n.º 2
0
        public async Task <LoadImageResult> LoadImageAsync(string externalId)
        {
            var imagesRepository = _unitOfWork.GetRepository <UploadedImage>();
            var imageDetails     = await imagesRepository.GetSingleOrDefaultAsync(i => i.ExternalId == externalId);

            if (imageDetails == null)
            {
                return(LoadImageResult.CreateUnsuccessful(LoadImageError.IncorrectExternalId));
            }

            var relativePath  = Path.Combine(_configuration.ImagesDirectory, imageDetails.FilePath);
            var fullPath      = Path.GetFullPath(relativePath);
            var isImageExists = File.Exists(fullPath);

            return(isImageExists
                ? LoadImageResult.CreateSuccessful(fullPath, imageDetails.MediaType)
                : LoadImageResult.CreateUnsuccessful(LoadImageError.ImageNotExists));
        }