Ejemplo n.º 1
0
        protected override void ApplyEvent(object @event)
        {
            switch (@event)
            {
            case NewOrderStarted e:
                Id       = e.OrderId;
                _date    = e.Date;
                _localId = e.LocalId;
                break;

            case OrderItemAdded e:
                _items.Add(new OrderItem {
                    ItemName   = e.ItemName,
                    PersonName = e.PersonName,
                    AddedAt    = e.AddedAt
                });
                break;

            case OrderResponsiblePersonSelected e:
                _responsiblePerson = e.PersonName;
                break;

            case OrderResponsiblePersonRemoved e:
                _responsiblePerson = null;
                break;

            case OrderItemRemoved e:
                _items.Remove(FindItemByPerson(e.PersonName));
                break;
            }
        }
 public static OrderId From(string localId, OrderDate date)
 {
     if (string.IsNullOrWhiteSpace(localId))
     {
         throw new DomainException("Local id cannot be empty", ErrorCode.IdCannotBeEmpty);
     }
     return(new OrderId($"{localId}-{date.Value:yyyyMMdd}"));
 }
        public async Task <string> Handle(OrderItem cmd)
        {
            var orderId = OrderId.From(cmd.LocalId, OrderDate.Today(_timeProvider));
            var order   = await _repository.LoadById(orderId.Value)
                          ?? new Order(orderId, cmd.LocalId, new OrderDate(_timeProvider.UtcNow.Date));

            order.OrderNewItem(cmd.ItemName, cmd.PersonName, addedAt: _timeProvider.UtcNow);

            await _repository.Save(order, cmd.CommandId);

            return(orderId.Value);
        }
Ejemplo n.º 4
0
 public Order(OrderId orderId, string localId, OrderDate date)
 {
     Publish(new NewOrderStarted(orderId, localId, date));
 }