コード例 #1
0
        private void SeedChatMessages(User user)
        {
            if (_chatRepository.Any())
            {
                var chats = _chatRepository.GetAll();

                foreach (var chat in chats)
                {
                    var message = GenerateRandomMessage(user);
                    message.ChatId = chat.Id;

                    _messageStore.Add(message);
                }
            }
        }
コード例 #2
0
        public override void Seed()
        {
            if (_chatRepository.Any() || !_userRepository.Any())
            {
                return;
            }

            var chats = new[]
            {
                new Chat()
                {
                    Id      = Guid.NewGuid(),
                    GroupId = new Guid("c49ff16c-842c-4c13-853c-acea6ee4d28d")
                },
                new Chat()
                {
                    Id      = Guid.NewGuid(),
                    GroupId = new Guid("8f10e5e0-02f6-47cc-84c7-cd4e5b06792f")
                },
                new Chat()
                {
                    Id      = Guid.NewGuid(),
                    GroupId = new Guid("3348dce8-26f0-4da5-b683-f0dedb462d62")
                }
            };

            var users = _userRepository.GetAll();

            foreach (var user in users)
            {
                foreach (var chat in chats)
                {
                    _chatUserRepository.Add(new ChatUser(user, chat));
                }
            }

            var author = users.First();

            foreach (var chat in chats)
            {
                var group = _groupRepository.Get(chat.GroupId);
                _chatEventService.AddChatCreatedEvent(group, author, chat);
            }
        }