Beispiel #1
0
        public static bool InsertRequest(UserRegisteration insertUser)
        {
            try
            {
                using (DbConnection conn = provider.CreateConnection())
                {
                    conn.ConnectionString = connString;
                    conn.Open();

                    using (DbCommand cmd = conn.CreateCommand())
                    {
                        string sqlQuery;
                        sqlQuery = "INSERT INTO Register_Requests" +
                               "(Building,Apartment,Name,ContactNo,EMail, Status) " +
                               "VALUES(@build,@apartment,@fullName,@mobile,@email, 'pending')";

                        if (parmPrefix != "@")
                        {
                            sqlQuery = sqlQuery.Replace("@", parmPrefix);
                        }
                        cmd.CommandText = sqlQuery;
                        cmd.CommandType = CommandType.Text;

                        DbParameter sNewId = provider.CreateParameter();
                        sNewId.ParameterName = parmPrefix + "build";
                        sNewId.Value = insertUser.Building;
                        cmd.Parameters.Add(sNewId);

                        DbParameter sUserName = provider.CreateParameter();
                        sUserName.ParameterName = parmPrefix + "apartment";
                        sUserName.Value = insertUser.Apartment;
                        cmd.Parameters.Add(sUserName);

                        DbParameter sFullName = provider.CreateParameter();
                        sFullName.ParameterName = parmPrefix + "fullName";
                        sFullName.Value = insertUser.Name;
                        cmd.Parameters.Add(sFullName);

                        DbParameter sMobile = provider.CreateParameter();
                        sMobile.ParameterName = parmPrefix + "mobile";
                        sMobile.Value = insertUser.ContactNo;
                        cmd.Parameters.Add(sMobile);

                        DbParameter sAddress = provider.CreateParameter();
                        sAddress.ParameterName = parmPrefix + "email";
                        sAddress.Value = insertUser.Email;
                        cmd.Parameters.Add(sAddress);

                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();
                    }
                    conn.Close();
                }
                return true;
            }
            catch (Exception exp)
            {
                return false;
            }
        }
Beispiel #2
0
        public static bool UpdateRequest(UserRegisteration insertUser)
        {
            try
            {
                using (DbConnection conn = provider.CreateConnection())
                {
                    conn.ConnectionString = connString;
                    conn.Open();

                    using (DbCommand cmd = conn.CreateCommand())
                    {
                        string sqlQuery;
                        sqlQuery = "UPDATE Register_Requests SET " +
                               "Status = @stat WHERE Building = @build AND Apartment = @apartment";

                        if (parmPrefix != "@")
                        {
                            sqlQuery = sqlQuery.Replace("@", parmPrefix);
                        }
                        cmd.CommandText = sqlQuery;
                        cmd.CommandType = CommandType.Text;

                        DbParameter sNewId = provider.CreateParameter();
                        sNewId.ParameterName = parmPrefix + "build";
                        sNewId.Value = insertUser.Building;
                        cmd.Parameters.Add(sNewId);

                        DbParameter sUserName = provider.CreateParameter();
                        sUserName.ParameterName = parmPrefix + "apartment";
                        sUserName.Value = insertUser.Apartment;
                        cmd.Parameters.Add(sUserName);

                        DbParameter sStatus = provider.CreateParameter();
                        sStatus.ParameterName = parmPrefix + "stat";
                        sStatus.Value = insertUser.Status;
                        cmd.Parameters.Add(sStatus);

                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();
                    }
                    conn.Close();
                }
                return true;
            }
            catch (Exception exp)
            {
                return false;
            }
        }