/// <summary>
        /// gets a customer objects from the database given a USERNAME/EMAIL of the customer
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public static Customer GetCustomer(string UserName)
        {
            Customer cust = null;

            SqlConnection connect = MarinaDB.GetConnection();

            string query = "SELECT ID, FirstName, LastName, Phone, City, UserName FROM CUSTOMER WHERE UserName = @UserName";

            using (SqlCommand cmd = new SqlCommand(query, connect))
            {
                connect.Open();
                cmd.Parameters.AddWithValue("@UserName", UserName);
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow);

                if (reader.Read())
                {
                    cust = new Customer()
                    {
                        UserName  = reader["UserName"].ToString(),
                        ID        = (int)reader["ID"],
                        FirstName = reader["FirstName"].ToString(),
                        LastName  = reader["LastName"].ToString(),
                        Phone     = reader["Phone"].ToString(),
                        City      = reader["City"].ToString(),
                    };
                }

                reader.Close();
                connect.Close();
            }

            return(cust);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inserts a lease into the DB given a SLIP and CUSTOMER object
        /// </summary>
        /// <param name="slip">the slip to add to the lease</param>
        /// <param name="customer">the customer assigned to the slip</param>
        /// <returns></returns>
        public static bool InsertLease(Slip slip, Customer customer)
        {
            SqlConnection connect = MarinaDB.GetConnection();

            //if customer or slip is null, return false
            if (Object.Equals(customer, null) || Object.Equals(slip, null))
            {
                return(false);
            }

            string query = "INSERT INTO LEASE(SlipID,CustomerID) Values(@SlipID,@CustomerID)";

            using (SqlCommand cmd = new SqlCommand(query, connect))
            {
                cmd.Parameters.AddWithValue("@SlipID", slip.ID);
                cmd.Parameters.AddWithValue("@CustomerID", customer.ID);
                connect.Open();
                int rowsAffected = cmd.ExecuteNonQuery();

                if (rowsAffected == 1)
                {
                    return(true);
                }
                return(false);
            }
        }