Example #1
0
        public Task <AsyncTaskResult> HandleAsync(SpecificationsAddedEvent 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.SpecificationTable, transaction));

                    //插入新的规格记录
                    foreach (var specification in evnt.Specifications)
                    {
                        tasks.Add(connection.InsertAsync(new
                        {
                            Id = specification.Id,
                            GoodsId = evnt.AggregateRootId,
                            Name = specification.Info.Name,
                            Value = specification.Info.Value,
                            Price = specification.Info.Price,
                            OriginalPrice = specification.Info.OriginalPrice,
                            Benevolence = specification.Info.Benevolence,
                            Stock = specification.Stock,
                            Number = specification.Info.Number,
                            Thumb = specification.Info.Thumb,
                            BarCode = specification.Info.BarCode,
                            AvailableQuantity = specification.Stock
                        }, ConfigSettings.SpecificationTable, transaction));
                    }
                    Task.WaitAll(tasks.ToArray());
                }
            }));
        }
Example #2
0
 private void Handle(SpecificationsAddedEvent evnt)
 {
     _specifications = evnt.Specifications;
 }
Example #3
0
 /// <summary>
 /// 编辑规格下架商品
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public Task <AsyncTaskResult> HandleAsync(SpecificationsAddedEvent evnt)
 {
     return(_commandService.SendAsync(
                new UpdateStatusCommand(evnt.AggregateRootId, GoodsStatus.UnVerify)));
 }