Esempio n. 1
0
        public DirectChat CreateDirectChat(string participant1, string participant2)
        {
            var chat = GetDirectChat(participant1, participant2);

            if (chat != null)
            {
                throw new ChatAlreadyExistException();
            }

            chat = new DirectChat()
            {
                ChatMembers = new List <ChatMember>()
            };
            _chatRepo.Add(chat);

            chat.ChatMembers.Add(new ChatMember()
            {
                Chat = chat,
                User = _userRepo.GetOne(participant1)
            });

            chat.ChatMembers.Add(new ChatMember()
            {
                Chat = chat,
                User = _userRepo.GetOne(participant2)
            });

            _chatRepo.Save(chat);

            return(chat);
        }