public enum StandardDeliveryState
{
Placed,
Prepared,
Dispatched,
Delivered,
}
public class StandardDeliveryContext: IOrderState
{
public static OrderRepository OrderRepository { get; set; }
public static void Init(OrderRepository _orderRepository)
{
OrderRepository = _orderRepository;
}
public int customerId { get; set; }
public int orderId { get; set; }
public DateTime placedOrderDate { get; set; }
private IOrderState process;
private StandardDeliveryState state;
public StandardDeliveryState State
{
get => state;
set
{
state = value;
switch (state)
{
case StandardDeliveryState.Placed:
process = new PreparedOrder(this);
break;
case StandardDeliveryState.Dispatched:
process = new DispatchOrder(this);
break;
case StandardDeliveryState.Delivered:
process = new Delivered(this);
break;
}
}
}
public void PreparedOrder(this)
{
process.PreparedOrder(placedOrderDate);
}
public void DispatchOrder(DateTime placedOrderDate)
{
process.DispatchOrder(placedOrderDate);
}
public void Delivered(DateTime placedOrderDate)
{
process.Delivered(placedOrderDate);
}
}