public async Task Upload(IFormFile photo, StoryView storyView)
        {
            var storyId = NewId.Next().ToGuid();

            var storyModel = _mapper.Map <Story>(storyView);

            storyModel.Id          = storyId;
            storyModel.ImagePath   = $"{_s3Settings.ServiceURL}/{_s3Settings.BucketName}/{storyId.ToString()}";
            storyModel.DateCreated = DateTime.Now;

            await Task.WhenAll(_storiesRepository.Upload(storyModel),
                               _feedService.AddStoryToFeed(storyModel.UserId, storyModel),
                               _amazonS3Repository.Upload(photo, storyId.ToString()));
        }
Esempio n. 2
0
        public async Task Upload(IFormFile photo, PhotoView photoView)
        {
            var photoId = NewId.Next().ToGuid();
            await _amazonS3Repository.Upload(photo, photoId.ToString());

            var photoModel = _mapper.Map <Photo>(photoView);

            photoModel.Id          = photoId;
            photoModel.ImagePath   = $"{_s3Settings.ServiceURL}/{_s3Settings.BucketName}/{photoId.ToString()}";
            photoModel.DateCreated = DateTime.Now;

            await Task.WhenAll(_photosRepository.Upload(photoModel),
                               _hashtagsService.AddNewHashtags(photoId, photoModel.Description),
                               _feedService.AddPhotoToFeed(photoModel.UserId, photoModel));
        }
Esempio n. 3
0
        public async Task Create(UserView userView, IFormFile avatar = null)
        {
            if (string.IsNullOrWhiteSpace(userView.Password))
            {
                throw new ArgumentException("Password is required");
            }
            if (userView.Username.Length < 3)
            {
                throw new ArgumentException("Username length < 3");
            }
            if (await _usersRepository.GetUserByName(userView.Username) != null)
            {
                throw new ArgumentException("Username \"" + userView.Username + "\" is already taken");
            }
            if (await _usersRepository.GetUserByEmail(userView.Email) != null)
            {
                throw new ArgumentException("Email \"" + userView.Email + "\" is already taken");
            }

            _cryptographyService.CreatePasswordHash(userView.Password, out var passwordHash, out var passwordSalt);

            userView.Id = NewId.Next().ToGuid().ToString();
            var user = _mapper.Map <User>(userView);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            if (avatar != null)
            {
                await _amazonS3Repository.Upload(avatar, userView.Id);

                user.AvatarPath = $"{_s3Settings.ServiceURL}/{_s3Settings.BucketName}/{userView.Id}";
            }

            await _usersRepository.AddUser(user);
        }