Пример #1
0
        /// <summary>
        /// Add a PackageProductSupplier to the DB
        /// </summary>
        /// <param name="packageId"></param>
        /// <param name="productSupplierId"></param>
        /// <returns></returns>
        public static bool Add(PackageProductSupplier packageProductSupplier)
        {
            if (Object.Equals(packageProductSupplier, null))
            {
                return(false);
            }

            string query =
                "INSERT INTO Packages_Products_Suppliers(PackageId, ProductSupplierId) " +
                "Values(@PackageId,@ProductSupplierId)";

            int rowsUpdated;

            SqlConnection connect = TravelExpertsConnection.GetConnection();

            using (SqlCommand cmd = new SqlCommand(query, connect))
            {
                cmd.Parameters.AddWithValue("@PackageId", packageProductSupplier.PackageId);
                cmd.Parameters.AddWithValue("@ProductSupplierId", packageProductSupplier.ProductSupplierId);

                connect.Open();

                rowsUpdated = cmd.ExecuteNonQuery();

                connect.Close();
            }

            //no rows updated.
            if (rowsUpdated == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #2
0
        public static PackageProductSupplier Get(PackageProductSupplier packageProductSupplier)
        {
            if (Object.Equals(packageProductSupplier, null))
            {
                return(null);
            }

            PackageProductSupplier package = null;

            SqlConnection con = TravelExpertsConnection.GetConnection();

            string command =
                "SELECT PackageId, ProductSupplierId " +
                "FROM Packages_Products_Suppliers " +
                "WHERE PackageId = @PackageId " +
                "AND ProductSupplierId = @ProductSupplierId";

            using (SqlCommand cmd = new SqlCommand(command, con))
            {
                con.Open();
                cmd.Parameters.AddWithValue("@PackageId", packageProductSupplier.PackageId);
                cmd.Parameters.AddWithValue("@ProductSupplierId", packageProductSupplier.ProductSupplierId);

                SqlDataReader read = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

                if (read.Read())
                {
                    package = new PackageProductSupplier()
                    {
                        PackageId         = (int)read["PackageId"],
                        ProductSupplierId = (int)read["ProductSupplierId"]
                    };
                }
            } // close command
            return(package);
        }