示例#1
0
 public static MessageVM MapMessageToViewModel(Message message, string userName)
 {
     return new MessageVM()
     {
         MessageId = message.Id.ToString(),
         Username = userName,
         Content = message.Content,
         SentOn = message.SentOn
     };
 }
示例#2
0
        public async Task<Message> SendNewMessage(string conversationId, string userId, string message)
        {
            var userObjectId = userId.ToObjectId();
            var conversationObjectId = conversationId.ToObjectId();

            var existingConversation = await GetConversationById(conversationId);

            var newMessage = new Message()
            {
                Id = ObjectId.GenerateNewId(),
                Content = message,
                UserIdFrom = userObjectId,
                SentOn = DateTime.Now
            };

            existingConversation.Messages.Add(newMessage);

            await _repository.Conversations.ReplaceOneAsync(c => c.Id == conversationObjectId, existingConversation);

            return newMessage;
        }