Skip to content

Instantly share code, notes, and snippets.

@ToJans
Created January 23, 2012 21:45
Show Gist options
  • Save ToJans/1665695 to your computer and use it in GitHub Desktop.
Save ToJans/1665695 to your computer and use it in GitHub Desktop.
uh oh, blommekes uses CQRS from now on #OverArchitecture /cc @yreynhout ;)
using MinimalisticCQRS.Infrastructure;
namespace Blommekes.Domain.Entities
{
public class Order : AR
{
private bool OrderClosed;
enum OrderStatus
{
None,
ProductAddedToOrder,
PaymentRequested,
PaymentAccepted,
PaymentCanceled,
PaymentTimedOut,
}
private string ProductId = null;
private OrderStatus Status= OrderStatus.None;
private string PaymentId;
private decimal TotalPrice;
public void RegisterOrder()
{
Guard.Against(this.Status >= OrderStatus.PaymentRequested, "A payment has already been launched for this order");
Apply.OrderRegistered(OrderId: this.Id);
}
public void AddProduct(string ProductId)
{
Guard.Against(this.Status >= OrderStatus.PaymentRequested, "A payment has already been launched for this order");
Apply.ProductAddedToOrder(ProductId, OrderId: this.Id);
}
public void RequestPayment(string PaymentId,decimal TotalPrice)
{
Guard.Against(this.Status < OrderStatus.ProductAddedToOrder, "This order does not yet contain any products");
Guard.Against(this.Status >= OrderStatus.PaymentRequested, "A payment has already been launched for this order");
Apply.PaymentRequested(PaymentId, TotalPrice, OrderId: this.Id);
}
public void AcceptPayment(string PaymentId,string ProductId,decimal TotalPrice)
{
Guard.Against(this.Status != OrderStatus.PaymentRequested, "This order is currently not in the payment request status");
Guard.Against(this.PaymentId != PaymentId,"There is a mismatch between the payment id request and response");
Guard.Against(this.ProductId != ProductId,"There is a mismatch between the products for the request and response");
Guard.Against(this.TotalPrice != TotalPrice,"There is a mismatch between the price for the request and response");
Apply.PaymentAccepted(OrderId: this.Id);
}
public void CancelPayment(string PaymentId, string ProductId, decimal TotalPrice)
{
Guard.Against(this.Status != OrderStatus.PaymentRequested, "This order is currently not in the payment request status");
Guard.Against(this.PaymentId != PaymentId, "There is a mismatch between the payment id request and response");
Guard.Against(this.ProductId != ProductId, "There is a mismatch between the products for the request and response");
Guard.Against(this.TotalPrice != TotalPrice, "There is a mismatch between the price for the request and response");
Apply.PaymentCanceled(OrderId: this.Id);
}
public void ReportPaymentTimeout(string PaymentId)
{
Guard.Against(this.Status != OrderStatus.PaymentRequested, "This order is currently not in the payment request status");
Guard.Against(this.PaymentId != PaymentId, "There is a mismatch between the payment id request and response");
Apply.PaymentTimedOut(PaymentId,OrderId: this.Id);
}
void OnOrderRegistered()
{
this.Status = OrderStatus.None;
}
void OnProductAddedToOrder(string ProductId)
{
this.ProductId = ProductId;
}
void OnPaymentRequested(string PaymentId,decimal TotalPrice)
{
this.Status = OrderStatus.PaymentRequested;
this.PaymentId = PaymentId;
this.TotalPrice = TotalPrice;
}
void OnPaymentAccepted()
{
this.Status = OrderStatus.PaymentAccepted;
}
void OnPaymentCanceled()
{
this.Status = OrderStatus.PaymentCanceled;
}
}
}
@ToJans
Copy link
Author

ToJans commented Jan 26, 2012

Removed it again #overarchitecture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment