Created
January 10, 2011 05:40
-
-
Save jmarnold/772421 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderProcessingModule | |
{ | |
public void Process(OrderStatusMessage orderStatusMessage) | |
{ | |
string connectionString = ConfigurationManager.ConnectionStrings["Main"].ConnectionString; | |
Order order = null; | |
using(var connection = new SqlConnection(connectionString)) | |
{ | |
order = FetchData(orderStatusMessage, connection); | |
} | |
if(order.IsInterational) | |
{ | |
ProcessInternationalOrder(order); | |
} | |
else if(order.LineItems.Count() > 10) | |
{ | |
ProcessLargeDomesticOrder(order); | |
} | |
else | |
{ | |
ProcessRegularDomesticOrder(order); | |
} | |
if(order.IsReadyToShip()) | |
{ | |
var gateway = new ShippingGateway(); | |
var message = CreateShipmentMessageForOrder(order); | |
gateway.SendShipment(message); | |
} | |
} | |
private ShipmentMessage CreateShipmentMessageForOrder(Order order) | |
{ | |
throw new NotImplementedException(); | |
} | |
private Order FetchData(OrderStatusMessage orderStatusMessage, SqlConnection connection) | |
{ | |
using(var cmd = connection.CreateCommand()) | |
{ | |
cmd.CommandText = "SELECT * FROM Order WHERE OrderId = @OrderId"; | |
cmd.Parameters.AddWithValue("@OrderId", orderStatusMessage.OrderId); | |
using(var reader = cmd.ExecuteReader()) | |
{ | |
if (!reader.NextResult()) | |
{ | |
return null; | |
} | |
var order = new Order(); | |
order.OrderId = reader.GetInt32(reader.GetOrdinal("OrderId")); | |
return order; | |
} | |
} | |
} | |
private void ProcessInternationalOrder(Order order) | |
{ | |
} | |
private void ProcessLargeDomesticOrder(Order order) | |
{ | |
} | |
private void ProcessRegularDomesticOrder(Order order) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment