public override void Execute(ICommand cmd, IEventSourceRepository repository)
        {
            var c = cmd.MapToCommand <ChangeProductQuantityInOrderItemCommand>();

            //Arrange
            var order = repository.GetById <Order>(c.AggregateRootId);

            var product = repository.GetById <Product>(c.ProductId);

            var customer = repository.GetById <Customer>(c.CustomerId);

            var quantity = order.GetQuantityInSelectedOrderItem(c.RowId);

            var totalAmount = order.GetTotalAmountInSelectedOrderItem(c.RowId);

            var newtotalAmount = product.GetTotalAmount(c.Quantity);

            //Act
            customer.IncreaseCashBalance(totalAmount);

            product.IncreaseStockBalance(quantity);

            order.ChangeProductQuantityInOrderItem(c.RowId, c.Quantity, newtotalAmount);

            customer.DecreaseCashBalance(newtotalAmount);

            product.DecreaseStockBalance(c.Quantity);
        }
        public override void Execute(ICommand cmd, IEventSourceRepository repository)
        {
            var c = cmd.MapToCommand <MakeNewOrderCommand>();

            var customer = repository.GetById <Customer>(c.CustomerId);

            Self.CreateNewOrder(customer.AggregateRootId);

            foreach (Guid item in c.Quantities.Keys)
            {
                var product = repository.GetById <Product>(item);

                var quantity = c.Quantities[item];

                var totalAmount = product.GetTotalAmount(quantity);

                if (customer.HasSufficientAmountToPurchase(totalAmount) && product.HasAvailableStockToPurchaseByQuantity(quantity))
                {
                    Self.AddOrderItem(quantity, totalAmount, customer.name, product.productName, product.AggregateRootId, customer.AggregateRootId);
                    customer.DecreaseCashBalance(totalAmount);
                    product.DecreaseStockBalance(quantity);
                }
                else
                {
                    throw new Exception("Insufficient amount to purchase");
                }
            }
        }
 public Auction Get(long id)
 {
     return(eventSourceRepository.GetById(id));
 }
 public Auction Get(Guid id)
 {
     return(repository.GetById(id));
 }