Exemple #1
0
        public bool JoinGroup(TRS_Domain.USER.Data client, Data myGroup)
        {
            bool output = false;

            //Try-Catch for safety:
            try
            {
                using (MySqlConnection Conn = _connectDb.GetConnection())
                {
                    //  Open Connection:
                    Conn.Open();

                    //  the incomplete query
                    MainQuery =
                        "INSERT INTO `group_members` (`GroupID`, `UserID`)" +
                        "VALUES(@GroupId, @ClientId)";


                    //  DEFINE the paramaters
                    MySqlParameter param1 = new MySqlParameter();
                    param1.ParameterName = "@ClientId";
                    param1.Value         = client.UserId;

                    MySqlParameter param2 = new MySqlParameter();
                    param2.ParameterName = "@GroupId";
                    param2.Value         = myGroup.GroupId;

                    //  build the command

                    MainCommand = new MySqlCommand(MainQuery, Conn);

                    //  add the parameters to the command
                    MainCommand.Parameters.Add(param1);
                    MainCommand.Parameters.Add(param2);

                    //  use the command
                    output = _connectDb.ExecuteNonQuery(MainCommand);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(output);
        }
Exemple #2
0
        public bool AddGroup(TRS_Domain.USER.Data client, string name, string description, byte[] bitMap, string region)
        {
            //  Define output:
            bool output = false;

            //Try-Catch for safety:
            try
            {
                using (MySqlConnection Conn = _connectDb.GetConnection())
                {
                    //  Open Connection:
                    Conn.Open();

                    //  the incomplete query
                    MainQuery =
                        "INSERT INTO `groups`(`GroupName`, `GroupDescription`, `GroupImage`,`GroupLeader`,`GroupRegion`) " +
                        "VALUES(@Name, @Description, @Image, @GroupLeader, @GroupRegion); " +
                        "INSERT INTO `group_members` (`GroupID`, `UserID`) " +
                        "VALUES((SELECT LAST_INSERT_ID()), @idclient)";
                    ;

                    //  DEFINE the paramaters
                    MySqlParameter param1 = new MySqlParameter();
                    param1.ParameterName = "@Name";
                    param1.Value         = name;

                    MySqlParameter param2 = new MySqlParameter();
                    param2.ParameterName = "@Description";
                    param2.Value         = description;

                    MySqlParameter param3 = new MySqlParameter();
                    param3.ParameterName = "@Image";
                    param3.Value         = bitMap;

                    MySqlParameter param4 = new MySqlParameter();
                    param4.ParameterName = "@GroupLeader";
                    param4.Value         = client.UserId;

                    MySqlParameter param5 = new MySqlParameter();
                    param5.ParameterName = "@GroupRegion";
                    param5.Value         = region;

                    MySqlParameter param6 = new MySqlParameter();
                    param6.ParameterName = "@idclient";
                    param6.Value         = client.UserId;

                    //  build the command
                    MainCommand = new MySqlCommand(MainQuery, Conn);

                    //  add the parameters to the command
                    MainCommand.Parameters.Add(param1);
                    MainCommand.Parameters.Add(param2);
                    MainCommand.Parameters.Add(param3);
                    MainCommand.Parameters.Add(param4);
                    MainCommand.Parameters.Add(param5);
                    MainCommand.Parameters.Add(param6);
                    //  use the command
                    output = _connectDb.ExecuteNonQuery(MainCommand);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(output);
        }