Ejemplo n.º 1
0
 private static ItemDto MapToDto(ItemReadModel entity)
 {
     return(new ItemDto
     {
         Id = entity.Id,
         Code = entity.Code,
         ItemTypeId = entity.ItemTypeId,
         Price = entity.Price,
         PercentOff = entity.PercentOff.Value,
         AmountOff = entity.AmountOff
     });
 }
Ejemplo n.º 2
0
        public async Task Handle(IList <object> newEvents)
        {
            foreach (var newEvent in newEvents)
            {
                switch (newEvent)
                {
                case ItemCreatedEvent itemCreatedEvent:
                {
                    var item = new ItemReadModel
                    {
                        Id         = itemCreatedEvent.Id,
                        Code       = itemCreatedEvent.Code,
                        ItemTypeId = itemCreatedEvent.ItemTypeId,
                        Price      = itemCreatedEvent.Price,
                        PercentOff = Percent.Zero
                    };
                    await _itemReadRepository.SaveAsync(item);

                    break;
                }

                case ItemAmountDiscountSetEvent itemAmountDiscountSetEvent:
                {
                    var item = await _itemReadRepository.GetAsync(itemAmountDiscountSetEvent.Id);

                    item.AmountOff = itemAmountDiscountSetEvent.AmountOff;
                    await _itemReadRepository.UpdateAsync(item);

                    break;
                }

                case ItemPercentageDiscountSetEvent itemPercentageDiscountSetEvent:
                {
                    var item = await _itemReadRepository.GetAsync(itemPercentageDiscountSetEvent.Id);

                    item.PercentOff = itemPercentageDiscountSetEvent.PercentOff;
                    await _itemReadRepository.UpdateAsync(item);

                    break;
                }
                }
            }
        }