コード例 #1
0
        public MessageViewModel AddMessage(MessageViewModel message)
        {
            var messageEntity = _repositoryManager.Messages.Add(new Message
            {
                ChatRoomId  = message.ChatRoomId.Value,
                MessageText = message.MessageText,
                SenderId    = message.UserId.Value
            });

            _repositoryManager.Complete();

            var user = _repositoryManager.Users.GetSingle(x => x.Id == message.UserId);

            return(new MessageViewModel
            {
                ChatRoomId = messageEntity.ChatRoomId,
                MessageText = messageEntity.MessageText,
                SentDate = messageEntity.SentTime,
                UserId = messageEntity.SenderId,
                UserName = user.FirstName
            });
        }