Skip to content

Order

Class public
Represents an order placed by a Customer, containing one or more OrderItem line items and tracking lifecycle state through OrderStatus.
Namespace SampleApi
Assembly SampleApi
Package v1.0.0.0
public class Order
An Order is always associated with a single customer via CustomerId. The order progresses through a linear state machine: PendingConfirmedShippedDelivered. At any point before shipping, the order can transition to Cancelled. The TotalPrice property is computed from the sum of each line item's quantity multiplied by its unit price. It is not persisted and is recalculated on every access.
Guid Order.CustomerId

Gets or sets the identifier of the Customer who placed this order.

This is a foreign key reference. The referenced customer must exist and be active at the time the order is created.
Guid Order.Id

Gets or sets the globally unique identifier for this order.

List<OrderItem> Order.Items

Gets or sets the collection of line items that make up this order.

An order must contain at least one item to be valid. Each item captures a product name, quantity, and unit price at the time of purchase.
DateTimeOffset
DateTimeOffset Order.OrderDate

Gets or sets the UTC date and time when the order was placed.

OrderStatus Order.Status

Gets or sets the current lifecycle status of the order.

Defaults to Pending. State transitions should be performed through the order processing pipeline, which validates that each transition is legal and raises the corresponding event via IOrderNotificationService.
decimal
decimal Order.TotalPrice

Gets the total price of the order, computed as the sum of each item's Quantity multiplied by its UnitPrice.

This is a calculated property and is not stored. It reflects the current state of the Items collection.

Creating an order with two line items:

var order = new Order
{
Id = Guid.NewGuid(),
CustomerId = customer.Id,
Items =
[
new OrderItem { ProductName = "Widget", Quantity = 3, UnitPrice = 9.99m },
new OrderItem { ProductName = "Gadget", Quantity = 1, UnitPrice = 24.95m }
]
};
// order.TotalPrice == 54.92m