Exemple #1
0
        private DbChatMessageStub PersistMessage(int otherUserId, string message)
        {
            var myUserId = this.GetMyUserId();

            // this is STUB. Normally you would go to the real database to get the my user and the other user
            var myUser    = dbUsersStub.FirstOrDefault(u => u.Id == myUserId);
            var otherUser = dbUsersStub.FirstOrDefault(u => u.Id == otherUserId);

            if (myUser == null || otherUser == null)
            {
                return(null);
            }

            var dbChatMessage = new DbChatMessageStub()
            {
                Date       = DateTime.UtcNow,
                Message    = message,
                UserFromId = myUserId,
                UserToId   = otherUserId,
                TenancyId  = myUser.TenancyId
            };

            // this is STUB. Normally you would add the dbMessage to the real database
            dbChatMessagesStub.Add(dbChatMessage);

            // normally you would save the database changes
            //this.db.SaveChanges();

            return(dbChatMessage);
        }
Exemple #2
0
 private ChatMessage GetChatMessage(DbChatMessageStub chatMessage, string clientGuid)
 {
     return(new ChatMessage()
     {
         Message = chatMessage.Message,
         UserFrom = this.GetChatUserFromDbUserId(chatMessage.UserFromId),
         UserTo = this.GetChatUserFromDbUserId(chatMessage.UserToId),
         ClientGuid = clientGuid
     });
 }