Пример #1
0
        public void EditUserProfileImages(User user, bool removeAvatar, bool removePhoto, HttpPostedFileBase avatarFile, HttpPostedFileBase photoFile)
        {
            var profile = _profileRepository.GetProfile(user.UserID);

            if (removeAvatar)
            {
                _userAvatarRepository.DeleteAvatarsByUserID(user.UserID);
                profile.AvatarID = null;
            }
            if (removePhoto)
            {
                _userImageRepository.DeleteImagesByUserID(user.UserID);
                profile.ImageID = null;
            }
            _profileRepository.Update(profile);

            if (avatarFile != null && avatarFile.ContentLength > 0)
            {
                _userAvatarRepository.DeleteAvatarsByUserID(user.UserID);
                var bytes    = _imageService.ConstrainResize(avatarFile.GetBytes(), _settingsManager.Current.UserAvatarMaxWidth, _settingsManager.Current.UserAvatarMaxHeight, 70);
                var avatarID = _userAvatarRepository.SaveNewAvatar(user.UserID, bytes, DateTime.UtcNow);
                profile.AvatarID = avatarID;
                _profileRepository.Update(profile);
            }

            if (photoFile != null && photoFile.ContentLength > 0)
            {
                _userImageRepository.DeleteImagesByUserID(user.UserID);
                var bytes   = _imageService.ConstrainResize(photoFile.GetBytes(), _settingsManager.Current.UserImageMaxWidth, _settingsManager.Current.UserImageMaxHeight, 70);
                var imageID = _userImageRepository.SaveNewImage(user.UserID, 0, _settingsManager.Current.IsNewUserImageApproved, bytes, DateTime.UtcNow);
                profile.ImageID = imageID;
                _profileRepository.Update(profile);
            }
        }
Пример #2
0
        public async Task EditAwardImage(string awardId, byte[] awardFile)
        {
            if (awardFile != null && awardFile.Length > 0)
            {
                await _awardImageRepository.DeleteImagesByAwardID(awardId);

                var bytes = _imageService.ConstrainResize(awardFile, _settingsManager.Current.UserImageMaxWidth, _settingsManager.Current.UserImageMaxHeight, 70);
                await _awardImageRepository.SaveNewImage(awardId, bytes, DateTime.UtcNow);
            }
        }
Пример #3
0
        public async Task EditUserProfileImages(User user, bool removeAvatar, bool removePhoto, byte[] avatarFile, byte[] photoFile)
        {
            var profile = await _profileRepository.GetProfile(user.UserID);

            if (removeAvatar)
            {
                await _userAvatarRepository.DeleteAvatarsByUserID(user.UserID);

                profile.AvatarID = null;
            }
            if (removePhoto)
            {
                await _userImageRepository.DeleteImagesByUserID(user.UserID);

                profile.ImageID = null;
            }
            await _profileRepository.Update(profile);

            if (avatarFile != null && avatarFile.Length > 0)
            {
                await _userAvatarRepository.DeleteAvatarsByUserID(user.UserID);

                var bytes    = _imageService.ConstrainResize(avatarFile, _settingsManager.Current.UserAvatarMaxWidth, _settingsManager.Current.UserAvatarMaxHeight, 70);
                var avatarID = await _userAvatarRepository.SaveNewAvatar(user.UserID, bytes, DateTime.UtcNow);

                profile.AvatarID = avatarID;
                await _profileRepository.Update(profile);
            }

            if (photoFile != null && photoFile.Length > 0)
            {
                await _userImageRepository.DeleteImagesByUserID(user.UserID);

                var bytes   = _imageService.ConstrainResize(photoFile, _settingsManager.Current.UserImageMaxWidth, _settingsManager.Current.UserImageMaxHeight, 70);
                var imageID = await _userImageRepository.SaveNewImage(user.UserID, 0, _settingsManager.Current.IsNewUserImageApproved, bytes, DateTime.UtcNow);

                profile.ImageID = imageID;
                await _profileRepository.Update(profile);
            }
        }