Skip to main content

Cleaning Up the Session

The last thing we need to do is remove the “Order” value from the %session object, by using the Kill command.

—Utils.CompleteOrder—
Utils.CompleteOrder
ClassMethod CompleteOrder()
{
    If $data(%session.Data("Order")) {
        // Open the current order object
        Set ord = ##class(Cinema.TicketOrder).%OpenId(%session.Data("Order"))

        // Update the number of tickets sold for each film in the order
        For i = 1:1:ord.Items.Count() {
            Set itm = ord.Items.GetAt(i)
            Set flm = itm.Show.Film
            Set flm.TicketsSold = flm.TicketsSold +
                itm.AdultTickets + itm.ChildTickets
            Set cat = flm.Category.%Id()
            Do flm.%Save()
        }
        // Mark order as complete and save
        Set ord.Complete=1
         Do ord.%Save()
        Kill %session.Data("Order")
    }
    Quit
}
FeedbackOpens in a new tab