Beispiel #1
0
        public void AddNewUser(UserModel user)
        {
            User newUser = new User {
                Name = user.Name, Password = user.Password
            };

            _context.User.Add(newUser);
            _context.SaveChanges();
        }
Beispiel #2
0
 public void AddUser(ISignedUp user)
 {
     using (var context = new TalkBackDBContext())
     {
         User userDB = ConvertToModel(user);
         context.Users.Add(userDB);
         context.SaveChanges();
     }
 }
        private void HandleChatMessageMsg(MessageModel msg, TalkBackDBContext dbContext)
        {
            // first check that the addressee is in the dictionary:
            WebSocket peer;

            if (!WebSocketMiddleware._sockets.TryGetValue(msg.To, out peer))
            {
                // not found -> send a ChatRequestResponse with failure:
                ChatRequestResponse resp = new ChatRequestResponse {
                    Success = false, ErrorMessage = "Chat peer is not online"
                };
                WebSocketMiddleware.SendStringAsync(_webSocket, resp.ToXml().ToString());
                return;
            }

            // save message in the log:
            Message dbMessage = new Message
            {
                Content      = msg.Content,
                ReceiverName = msg.To,
                SenderName   = msg.From,
                Time         = DateTime.Now
            };

            try
            {
                dbContext.Message.Add(dbMessage);
                dbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                //do nothing
            }

            // send the message to both sender and receiver:
            string strMsg = msg.ToXml().ToString();

            WebSocketMiddleware.SendStringAsync(_webSocket, strMsg);
            WebSocketMiddleware.SendStringAsync(peer, strMsg);

            return;
        }