Exemplo n.º 1
0
        /*
         * Saves a message in the database
         */
        private bool SaveMessage(Message msg, User user, NetworkStream stream)
        {
            bool success = true;

            byte[] receiveBuffer = new Byte[2];

            using (ViaChatEntities db = new ViaChatEntities())
            {
                msg.user_id = user.id;
                db.Messages.Add(msg);
                try
                {
                    db.SaveChanges();
                    SendResponse(true, "", stream);
                }
                catch (Exception e)
                {
                    success = false;
                    SendResponse(false, e.ToString(), stream);
                    Console.WriteLine(e);
                }
            }

            stream.Read(receiveBuffer, 0, receiveBuffer.Length); //Wait for user to receive message confirmation

            return(success);
        }
Exemplo n.º 2
0
        /*
         * Registers a user in the database
         * Returns true if success
         */
        private bool RegisterUser(User user, NetworkStream stream)
        {
            bool success = true;

            using (ViaChatEntities db = new ViaChatEntities())
            {
                db.Users.Add(user);
                try
                {
                    db.SaveChanges();
                    SendResponse(true, "", stream);
                }
                catch (Exception e)
                {
                    success = false;
                    SendResponse(false, e.ToString(), stream);
                    Console.WriteLine(e);
                }
            }

            return(success);
        }