Exemplo n.º 1
0
        public async Task <User> GetCurrentUserAsync(CurrentUserIdentityProvider currentUserIdentityProvider)
        {
            var userRepository      = _unitOfWork.UserRepository;
            var currentUserIdentity = currentUserIdentityProvider();
            var currentUser         = await userRepository.GetSingleOrDefaultAsync(u => u.Username == currentUserIdentity.Name);

            return(currentUser);
        }
Exemplo n.º 2
0
        public async Task <string> GetCurrentUserImageExternalIdAsync(CurrentUserIdentityProvider currentUserIdentityProvider)
        {
            var userRepository      = _unitOfWork.UserRepository;
            var currentUserIdentity = currentUserIdentityProvider();
            var currentUser         = await userRepository.GetSingleOrDefaultAsync(u => u.Username == currentUserIdentity.Name, u => u.ProfileImage);

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

            return("default-profile-image");
        }
Exemplo n.º 3
0
        public async Task <ServiceResult <UpdateProfileErrorType> > UpdateUserProfileAsync(CurrentUserIdentityProvider currentUserIdentityProvider, UpdateUserProfileDto dto)
        {
            var userRepository  = _unitOfWork.UserRepository;
            var imageRepostiory = _unitOfWork.GetRepository <UploadedImage>();

            var newImage = await imageRepostiory.GetFirstOrDefaultAsync(i => i.ExternalId == dto.UserProfileImageExternalId);

            if (newImage == null)
            {
                return(ServiceResult.CreateFailed(UpdateProfileErrorType.InvalidProfileImage));
            }

            var currentUser = await GetCurrentUserAsync(currentUserIdentityProvider);

            currentUser.ProfileImageId = newImage.Id;
            userRepository.Update(currentUser);
            await _unitOfWork.SaveAsync();

            return(ServiceResult.CreateSuccess <UpdateProfileErrorType>());
        }