public Task <AsyncTaskResult> HandleAsync(SpecificationReservedEvent evnt) { return(TryTransactionAsync(async(connection, transaction) => { var effectedRows = await connection.UpdateAsync(new { Version = evnt.Version, EventSequence = evnt.Sequence }, new { Id = evnt.AggregateRootId, //Version = evnt.Version - 1 }, ConfigSettings.GoodsTable, transaction); if (effectedRows == 1) { var tasks = new List <Task>(); //插入预定记录 foreach (var reservationItem in evnt.ReservationItems) { tasks.Add(connection.InsertAsync(new { GoodsId = evnt.AggregateRootId, ReservationId = evnt.ReservationId, SpecificationId = reservationItem.SpecificationId, Quantity = reservationItem.Quantity }, ConfigSettings.ReservationItemsTable, transaction)); } //更新规格的可用数量 foreach (var specificationAvailableQuantity in evnt.SpecificationAvailableQuantities) { tasks.Add(connection.UpdateAsync(new { AvailableQuantity = specificationAvailableQuantity.AvailableQuantity }, new { GoodsId = evnt.AggregateRootId, Id = specificationAvailableQuantity.SpecificationId }, ConfigSettings.SpecificationTable, transaction)); } Task.WaitAll(tasks.ToArray()); } })); }
/// <summary> /// 某个商品发来的预定成功消息 /// </summary> /// <param name="message"></param> /// <returns></returns> public Task <AsyncTaskResult> HandleAsync(SpecificationReservedEvent evnt) { //发送单个商品预定成功指令给订单 订单处理是否全部预定成功 return(_commandService.SendAsync(new ConfirmOneReservationCommand(evnt.ReservationId, evnt.AggregateRootId, true))); }
private void Handle(SpecificationReservedEvent evnt) { _reservations.Add(evnt.ReservationId, evnt.ReservationItems); }