html 定义列表dddt,DDD:订单管理 之 如何组织代码

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6

7 usingHappy.Domain;8 usingHappy.Domain.Tree;9 usingHappy.Infrastructure.ExtentionMethods;10 usingHappy.Example.Events.TestOrders;11

12 namespaceHappy.Example.Domain.TestOrders13 {14 public partial class TestOrder : AggregateRoot

15 {16 privateITestOrderState _orderState;17

18 protectedTestOrder() { }19

20 public TestOrder(string orderCode, stringcustomer)21 {22 orderCode.MustNotNullAndNotWhiteSpace("orderCode");23 customer.MustNotNullAndNotWhiteSpace("customer");24

25 this.Id =Guid.NewGuid();26 this.OrderCode =orderCode;27 this.Customer =customer;28 this.OrderState = TestOrderStateFactory.CreateUnCommittedTestOrderState(this);29 this.TestOrderDetails = new List();30 }31

32 public virtual System.String OrderCode { get; protected set; }33 public virtual System.String Customer { get; protected set; }34 public virtual System.Decimal Total { get; protected set; }35 public virtual System.String Status { get; protected set; }36 public virtual ICollection TestOrderDetails { get; protected set; }37

38 privateITestOrderState OrderState39 {40 get

41 {42 if (_orderState == null)43 {44 _orderState = TestOrderStateFactory.Create(this, this.Status);45 }46

47 return_orderState;48 }49 set

50 {51 _orderState =value;52 this.Status =value.Status;53 }54 }55

56 public voidAddTestOrderDetail(TestOrderDetail testOrderDetail)57 {58 this.OrderState.AddTestOrderDetail(testOrderDetail);59 }60

61 public void UpdateTestOrderDetail(Guid testOrderDetailId, decimalsubtotal)62 {63 this.OrderState.UpdateTestOrderDetail(testOrderDetailId, subtotal);64 }65

66 public voidRemoveTestOrderDetail(Guid testOrderDetailId)67 {68 this.OrderState.RemoveTestOrderDetail(testOrderDetailId);69 }70

71 public voidCommit()72 {73 this.OrderState.Commit();74 }75

76 public voidVerify()77 {78 this.OrderState.Verify();79 }80

81 private voidDoAddTestOrderDetail(TestOrderDetail testOrderDetail)82 {83 this.TestOrderDetails.Add(testOrderDetail);84

85 this.Total +=testOrderDetail.Subtotal;86 }87

88 private void DoUpdateTestOrderDetail(Guid testOrderDetailId, decimalsubtotal)89 {90 var testOrderDetail = this.TestOrderDetails.First(x => x.Id ==testOrderDetailId);91

92 this.Total -=testOrderDetail.Subtotal;93 testOrderDetail.Subtotal =subtotal;94 this.Total +=testOrderDetail.Subtotal;95 }96

97 private voidDoRemoveTestOrderDetail(Guid testOrderDetailId)98 {99 var testOrderDetail = this.TestOrderDetails.First(x => x.Id ==testOrderDetailId);100

101 this.TestOrderDetails.Remove(testOrderDetail);102 this.Total -=testOrderDetail.Subtotal;103 }104

105 private voidDoCommit()106 {107 this.OrderState = TestOrderStateFactory.CreatePendingVerificationTestOrderState(this);108 }109

110 private voidDoVerify()111 {112 this.OrderState = TestOrderStateFactory.CreateVerifiedTestOrderState(this);113

114 this.PublishEvent(newTestOrderVerified());115 }116 }117 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值