public OperationResult PlaceOrder(Product product, int quantity,
DateTimeOffset? deliverBy = null,
string instructions = "standard delivery")
{
if (product == null)
throw new ArgumentNullException("product");
if (quantity <= 0)
throw new ArgumentOutOfRangeException("quantity");
if (deliverBy <= DateTimeOffset.Now)
throw new ArgumentOutOfRangeException("deliverBy");
var success = false;
var orderTextBuilder = new StringBuilder("Order from Acme, Inc" +
System.Environment.NewLine +
"Product: " + product.ProductName +
System.Environment.NewLine +
"Quantity: " + quantity);
if (deliverBy.HasValue)
{
orderTextBuilder.Append( System.Environment.NewLine +
"Deliver By: " + deliverBy.Value.ToString("d"));
}
if (!String.IsNullOrWhiteSpace(instructions))
{
orderTextBuilder.Append( System.Environment.NewLine +
"Instructions: " + instructions);
}
var orderText = orderTextBuilder.ToString();
var emailService = new EmailService();
var confirmation = emailService.SendMessage("New Order", orderText,
this.Email);
if (confirmation.StartsWith("Message sent:"))
{
success = true;
}
var operationResult = new OperationResult(success, orderText);
return operationResult;
}