Skip to content

Instantly share code, notes, and snippets.

@tuannguyenssu
Created August 15, 2019 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuannguyenssu/60fa2f38cb9d786bdcdf884ae9a0b3c8 to your computer and use it in GitHub Desktop.
Save tuannguyenssu/60fa2f38cb9d786bdcdf884ae9a0b3c8 to your computer and use it in GitHub Desktop.
using System;
namespace GraphQLTest.Models
{
[Flags]
public enum OrderStatus
{
CREATED = 2,
PROCESSING = 4,
COMPLETED = 8,
CANCELLED = 16,
CLOSED = 32
}
public class Order
{
public string Id {get; set;}
public string Name {get; set;}
public int CustomerId {get; set;}
public OrderStatus Status {get; private set;} = OrderStatus.CREATED;
public void Start()
{
if (Status != OrderStatus.CREATED) {
throw new InvalidOperationException($"Order: {Id} cannot be started");
}
Status = OrderStatus.PROCESSING;
}
public void Complete() {
if (Status != OrderStatus.PROCESSING) {
throw new InvalidOperationException($"Order: {Id} cannot be completed");
}
Status = OrderStatus.COMPLETED;
}
public void Cancel() {
if (Status == OrderStatus.CANCELLED || Status == OrderStatus.CLOSED || Status == OrderStatus.COMPLETED) {
throw new InvalidOperationException($"Order: {Id} cannot be cancelled");
}
Status = OrderStatus.CANCELLED;
}
public void Close() {
if (Status != OrderStatus.COMPLETED) {
throw new InvalidOperationException($"Order: {Id} cannot be closed");
}
Status = OrderStatus.CLOSED;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment