Exemple #1
0
        /// <summary>
        /// Rents a MovieExemplar to a Customer.
        /// </summary>
        /// <param name="exemplar">instance of MovieExemplar class; must not be
        /// already rented</param>
        /// <param name="customer">instance of Customer class</param>
        /// <param name="days">an integer with number of days</param>
        /// <param name="fee">an decimal with rental fee</param>
        ///
        public void RentItem(MovieExemplar exemplar, Customer customer,
                             int days, decimal fee)
        {
            if (exemplar == null || customer == null)
            {
                return; // nothing to rent
            }

            if (exemplar.IsRented)
            {
                throw new Exception("Cannot rent item that is already rented.");
            }

            DateTime dueDate = DateTime.Now.AddDays(days);

            // Create RentedItem as assocation between MovieExemplar and Customer
            //
            RentedItem item = new RentedItem(exemplar, dueDate, fee);

            item.AddTo(customer);
        }
Exemple #2
0
        /// <summary>
        /// This method returns a list of rented items from the rental transactions with the specified StoreMemberID.
        /// </summary>
        /// <param name="storeMemberID">The ID of the StoreMember.</param>
        /// <returns>A list of rented items from the rental transactions with the specified StoreMemberID.</returns>
        public List <RentedItem> GetRentalTransactionsWithItemsByStoreMemberID(int storeMemberID)
        {
            List <RentedItem> rentedList      = new List <RentedItem>();
            string            selectStatement =
                "SELECT RentalTransaction.RentalID AS RentalID, RentalTransaction.DateOfRental AS DateOfRental, RentalTransaction.ScheduledReturn AS ScheduledReturn, " +
                "Employees.FName AS EmployeeFirst, Employees.LName AS EmployeeLast, FurnitureItem.Serial# AS ItemSerial, FurnitureItem.Description AS ItemDescription, " +
                "FurnitureItem.DailyRentalRate AS ItemPrice, RentedItem.Quantity AS ItemQuantity " +
                "FROM RentalTransaction " +
                "LEFT JOIN Employees ON RentalTransaction.EmployeeID=Employees.EmployeeID " +
                "LEFT JOIN RentedItem ON RentalTransaction.RentalID=RentedItem.RentalID " +
                "LEFT JOIN FurnitureItem ON RentedItem.Serial#=FurnitureItem.Serial# " +
                "WHERE RentalTransaction.MemberID=@memberID " +
                "ORDER BY RentalID ASC; ";

            using (SqlConnection connection = RentMeDBConnection.GetConnection())
            {
                connection.Open();
                using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
                {
                    selectCommand.Parameters.AddWithValue("@memberID", storeMemberID);
                    using (SqlDataReader reader = selectCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int        rentalID         = reader.GetInt32(0);
                            DateTime   dateOfRental     = (DateTime)reader["DateOfRental"];
                            DateTime   scheduledReturn  = (DateTime)reader["ScheduledReturn"];
                            string     employeeFullName = reader["EmployeeFirst"].ToString() + " " + reader["EmployeeLast"].ToString();
                            string     itemSerial       = reader["ItemSerial"].ToString();
                            string     itemDescription  = reader["ItemDescription"].ToString();
                            decimal    itemPrice        = reader.GetDecimal(7);
                            int        itemQuantity     = reader.GetInt32(8);
                            RentedItem rentedItem       = new RentedItem(rentalID, dateOfRental, scheduledReturn, employeeFullName, itemSerial, itemDescription, itemPrice, itemQuantity);
                            rentedList.Add(rentedItem);
                        }
                    }
                }
            }
            return(rentedList);
        }