예제 #1
0
        public void CreateStory(CreateStory createStory)
        {
            using (var transaction = _dbConnection.BeginTransaction())
            {
                var storyId = _storyRepository.CreateStory(_dbConnection, createStory);

                _storyRepository.AddUserToStory(_dbConnection, new AddUserToStory()
                {
                    IsCurrentTurn = false, StoryId = storyId, TurnOrder = 1, UserId = createStory.UserId
                });

                int counter = 1;
                foreach (var email in createStory.Emails)
                {
                    counter++;
                    var friendId = _userRepository.CreateUser(_dbConnection, new User()
                    {
                        Email = email
                    });
                    _userRepository.AddFriend(_dbConnection, createStory.UserId, friendId);
                    _storyRepository.AddUserToStory(_dbConnection, new AddUserToStory()
                    {
                        IsCurrentTurn = counter == 2, UserId = friendId, StoryId = storyId, TurnOrder = counter
                    });
                }
            }
        }