Пример #1
0
        public Message AddMessage(string chatName, string text, string from)
        {
            if (text.Length > 150 || string.IsNullOrWhiteSpace(text))
            {
                throw new MessageInvalidException(text);
            }

            var chat = _chatRepo.GetChats().SingleOrDefault(c => c.Name == chatName);
            var user = _userRepo.GetUsers().SingleOrDefault(c => c.Username == from);

            if (chat == null)
            {
                return(null);
            }

            var message = new Message(user, text);

            _chatRepo.AddMessage(chat, message);

            if (!chat.Participants.Any(p => p.Username == from))
            {
                _chatRepo.AddParticipant(chat, user);
            }

            return(message);
        }
Пример #2
0
        public async Task <ChatParticipantDto> CreateParticipant(ChatParticipantDto participant)
        {
            var cParticipant = _mapper.Map <ChatParticipant>(participant);

            bool result = await _repo.AddParticipant(cParticipant);

            if (result)
            {
                return(_mapper.Map <ChatParticipantDto>(cParticipant));
            }
            return(null);
        }