public Task <AsyncTaskResult> HandleAsync(GoodsParamsUpdatedEvent 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>(); //删除原来的参数记录 tasks.Add(connection.DeleteAsync(new { GoodsId = evnt.AggregateRootId }, ConfigSettings.GoodsParamTable, transaction)); //插入新的参数记录 foreach (var goodsParam in evnt.GoodsParams) { tasks.Add(connection.InsertAsync(new { Id = GuidUtil.NewSequentialId(), GoodsId = evnt.AggregateRootId, Name = goodsParam.Name, Value = goodsParam.Value }, ConfigSettings.GoodsParamTable, transaction)); } Task.WaitAll(tasks.ToArray()); } })); }
private void Handle(GoodsParamsUpdatedEvent evnt) { _goodsParams = evnt.GoodsParams; }