-
-
Save tuannguyenssu/60fa2f38cb9d786bdcdf884ae9a0b3c8 to your computer and use it in GitHub Desktop.
This file contains 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
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