Exemplo n.º 1
0
        public virtual void ReturnMoney()
        {
            Money moneyToReturn = MoneyInside.Allocate(MoneyInTransaction);

            MoneyInside       -= moneyToReturn;
            MoneyInTransaction = 0; // keeping it immutable
        }
Exemplo n.º 2
0
        public virtual void ReturnMonay()
        {
            var allocatedMoney = MoneyInside.Allocate(MoneyInTransaction);

            MoneyInTransaction = 0;
            MoneyInside       -= allocatedMoney;
        }
Exemplo n.º 3
0
        public void ReturnMoney()
        {
            var moneyToReturn = MoneyInside.Allocate(MoneyInTransaction);

            MoneyInside       -= moneyToReturn;
            MoneyInTransaction = 0;
        }
Exemplo n.º 4
0
        //public virtual void InsertMoney(Money money) => MoneyInTransaction += money;
        //public virtual void ReturnMoney() => MoneyInTransaction = None;
        public virtual void ReturnMoney()
        {
            Money moneyToRetun = MoneyInside.Allocate(MoneyInTransaction);

            MoneyInside       -= moneyToRetun;
            MoneyInTransaction = 0;
        }
Exemplo n.º 5
0
        public virtual void TakeMoney(decimal amount)
        {
            //TODO: Unit test for that case
            if (CanTakeMoney(amount) != string.Empty)
            {
                throw new InvalidOperationException();
            }

            Money output = MoneyInside.Allocate(amount);

            MoneyInside -= output;
            decimal amountWithCommission = CalculateAmountWithCommission(amount);

            MoneyCharged += amountWithCommission;
            //DomainEvents.Raise(new BalanceChangedEvent(amountWithCommission));


            //domain entity is no longer responsible for raising the event, it just saves it to the internal list.
            // creating an event is the responsibility of domain entities and dispatching it is the responsibility of infrastructure.
            AddDomainEvents(new BalanceChangedEvent(amountWithCommission));
            //if (amount < 1m)
            //{
            //    //decimal amountWithCommission = amount + CommissionRate;
            //    decimal amountWithCommission = CalculateAmountWithCommission(amount);
            //    MoneyCharged += amountWithCommission;
            //}
            //else
            //{
            //    //decimal amountWithCommission = amount + amount * CommissionRate;
            //    decimal amountWithCommission = CalculateAmountWithCommission(amount);
            //    MoneyCharged += amountWithCommission;
            //}
        }
Exemplo n.º 6
0
        public virtual void TakeMoney(decimal amount)
        {
            if (CanTakeMoney(amount) != string.Empty)
            {
                throw new InvalidOperationException();
            }

            Money output = MoneyInside.Allocate(amount);

            MoneyInside -= output;

            //decimal amountWithCommission = amount + amount * CommissionRate;
            decimal amountWithCommission = CalculateAmountWithComission(amount);

            MoneyCharged += amountWithCommission;

            //DomainEvents.Raise(new BalanceChangedEvent(amountWithCommission)); // classic approach to handling firing events
            // doesn't fit into the notion of Unit of Work

            // better approach

            AddDomainEvent(new BalanceChangedEvent(amountWithCommission));

            //  headOffice.Balance += amountWithCommission; // domain event to avoid bidirectional relationship between bounded contexts
        }
Exemplo n.º 7
0
        public virtual void ReturnMoney()
        {
            var meneyToReturn = MoneyInside.Allocate(MoneyInTransaction);

            MoneyInTransaction = 0;
            MoneyInside       -= meneyToReturn;
        }
Exemplo n.º 8
0
        public void RemoveMoney()
        {
            var moneyToReturn = MoneyInside.Allocate(
                MoneyInTransaction.Amount);

            MoneyInside -= moneyToReturn;
            SetToZeroAmountInTransaction();
        }
Exemplo n.º 9
0
        public virtual void TakeMoney(decimal amount)
        {
            MoneyInside -= MoneyInside.Allocate(amount);

            var amountWithCommission = CalculateAmountWithCommission(amount);

            MoneyCharged += amountWithCommission;

            AddDomainEvent(new BalanceChangedEvent(amountWithCommission));
        }
        public virtual void TakeMoney(decimal amount)
        {
            var output = MoneyInside.Allocate(amount);

            MoneyInside -= output;


            MoneyCharged += CalculateCommissionWithRate(amount);

            AddDomainEvent(new BalanceChangedEvent(MoneyCharged));
            //DomainEvents.Raise(new BalanceChangedEvent(MoneyCharged));
        }
Exemplo n.º 11
0
        public virtual void TakeMoney(decimal amount)
        {
            if (!MoneyInside.CanAllocate(amount))
            {
                throw new InvalidOperationException();
            }

            var allocatedMoney = MoneyInside.Allocate(amount);

            MoneyInside -= allocatedMoney;
            decimal amountWithCommision = CalculateAmountWithCommision(amount);

            MoneyCharged += amountWithCommision;
            AddDomainEvent(new BalanceChangedEvent(amountWithCommision));
        }
Exemplo n.º 12
0
        public virtual void TakeMoney(decimal amount)
        {
            if (CanTakeMoney(amount) != string.Empty)
            {
                throw new InvalidOperationException();
            }

            var output = MoneyInside.Allocate(amount);

            MoneyInside -= output;

            var amountWithCommission = CalculateAmountWithCommission(amount);

            MoneyCharged += amountWithCommission;
        }
Exemplo n.º 13
0
        public virtual void BuySnack(int position)
        {
            if (CanBySnack(position) != string.Empty)
            {
                throw new InvalidOperationException();
            }

            var slot = GetSlot(position);

            slot.SnackPile = slot.SnackPile.SubtractOne();
            var change = MoneyInside.Allocate(MoneyInTransaction - slot.SnackPile.Price);

            MoneyInside       -= change;
            MoneyInTransaction = 0;
        }
Exemplo n.º 14
0
        public virtual void BuySnack(int position)
        {
            if (CanBuySnack(position) != string.Empty)
            {
                throw new InvalidOperationException();
            }

            Slot slot = GetSlot(position);

            slot.SnackPile = slot.SnackPile.SubstractOne();
            var change = MoneyInside.Allocate(MoneyInTransaction - slot.SnackPile.Price);

            MoneyInside       -= change;
            MoneyInTransaction = 0; //TODO: insetd of this should Return Money
        }
Exemplo n.º 15
0
        public void TakeMoney(decimal amount)
        {
            if (CanTakeMoney(amount) != string.Empty)
            {
                throw new InvalidOperationException();
            }
            Money output = MoneyInside.Allocate(amount);

            MoneyInside -= output;

            decimal amountWithCommission = CalculateAmountWithCommission(amount);

            MoneyCharged += amountWithCommission;

            AddDomainEvent(new BalanceChangedEvent(amountWithCommission));
        }
Exemplo n.º 16
0
        public virtual void BuySnack(int position)
        {
            if (!CanBuySnack(position))
            {
                return;
            }

            var slot = GetSlot(position);

            slot.SnackPile = slot.SnackPile.SubtaractOne();

            var change = MoneyInside.Allocate(MoneyInTransaction - slot.SnackPile.Price);

            MoneyInside       -= change;
            MoneyInTransaction = 0;
        }
Exemplo n.º 17
0
        public virtual void Withdrawal(decimal amount)
        {
            if (!CanWithdrawal(amount))
            {
                return;
            }

            var output = MoneyInside.Allocate(amount);

            MoneyInside -= output;

            var amountWithCommision = amount + CalculateCommision(amount);

            MoneyCharged += amountWithCommision;

            AddDomainEvent(new BalanceChangedEvent(amountWithCommision, Constants.HeadOfficeId));
        }
Exemplo n.º 18
0
        public virtual void TakeMoney(decimal amount)
        {
            if (!string.IsNullOrEmpty(CanTakeMoney(amount)))
            {
                throw new InvalidOperationException();
            }

            var output = MoneyInside.Allocate(amount);

            MoneyInside -= output;

            var amountWithCommission = CalculateAmountWithCommission(amount);

            MoneyCharged += amountWithCommission;

            //DomainEvents.Raise(new BalanceChangedEvent(amountWithCommission)); // Disparando evento do valor para o domínio.

            AddDomainEvent(new BalanceChangedEvent(amountWithCommission));
        }
Exemplo n.º 19
0
        public virtual void BuySnack(int position)
        {
            Slot slot = GetSlot(position);

            if (slot.SnackPile.Price > MoneyInTransaction)
            {
                throw new InvalidOperationException();
            }

            slot.SnackPile = slot.SnackPile.SubtractOne();

            Money change = MoneyInside.Allocate(MoneyInTransaction - slot.SnackPile.Price);

            if (change.Amount < MoneyInTransaction - slot.SnackPile.Price)
            {
                throw new InvalidOperationException();
            }
            MoneyInside       -= change;
            MoneyInTransaction = 0m;
        }
        public virtual void TakeMoney(decimal amount)
        {
            if (CanTakeMoney(amount) != string.Empty)
            {
                throw new InvalidOperationException();
            }

            Money output = MoneyInside.Allocate(amount);

            MoneyInside -= output;

            decimal amountWithCommission = CaluculateAmountWithCommission(amount);

            MoneyCharged += amountWithCommission;

            ////old approach
            //DomainEvents_old.Raise(new BalanceChangedEvent(amountWithCommission));

            //better abstraction
            AddDomainEvent(new BalanceChangedEvent(amountWithCommission));
        }
Exemplo n.º 21
0
        public virtual void BuySnack(int position)
        {
            var slot = Slots.Single(x => x.Position == position);

            if (slot.SnackPile.Price > MoneyInTransaction)
            {
                throw new InvalidOperationException();
            }

            slot.SnackPile = slot.SnackPile.SubtractOne();

            var change = MoneyInside.Allocate(MoneyInTransaction - slot.SnackPile.Price);

            if (change.Amount < MoneyInTransaction - slot.SnackPile.Price)
            {
                throw new InvalidOperationException();
            }

            MoneyInside       -= change;
            MoneyInTransaction = 0;
        }
Exemplo n.º 22
0
        public virtual void BuySnack(int position)
        {
            if (CanBuySnack(position) != string.Empty)
            {
                throw new InvalidOperationException();
            }

            Slot slot = GetSlot(position);

            // slot.Quantity--;
            //if (slot.SnackPile.Price > MoneyInTransaction) now we don't need these checks
            //    throw new InvalidOperationException();
            slot.SnackPile = slot.SnackPile.SubstractOne();
            // MoneyInside += MoneyInTransaction;
            // MoneyInTransaction = None;
            Money change = MoneyInside.Allocate(MoneyInTransaction - slot.SnackPile.Price);

            //if (change.Amount < MoneyInTransaction - slot.SnackPile.Price)  now we don't need these checks
            //    throw new InvalidOperationException();
            MoneyInside       -= change;
            MoneyInTransaction = 0;
        }
Exemplo n.º 23
0
        public void BuySnack(int position)
        {
            if (!CanBuySnak(position))
            {
                throw new CannotBuySnakException();
            }

            var slot = GetSlot(position);

            slot.SubtractOneSnak();

            var allocatedCharge = MoneyInside.Allocate(
                MoneyInTransaction.Amount - slot.GetItemPrice());

            MoneyInside -= allocatedCharge;
            MoneyInside += MoneyInTransaction;

            SetToZeroAmountInTransaction();

            AddDomainEvent(new SnackBoughtDomainEvent(
                               slot.SnackType.Id, slot.GetItemPrice()));
        }
Exemplo n.º 24
0
        public virtual void BuySnack(int position)
        {
            var slot = GetSlot(position);

            if (slot.SnackPile.Price > MoneyInTransaction)
            {
                throw new InvalidOperationException();
            }

            var change   = MoneyInTransaction - slot.SnackPile.Price;
            var allocate = MoneyInside.Allocate(change);

            if (allocate.Amount < change)
            {
                throw new InvalidOperationException();
            }

            slot.SnackPile = slot.SnackPile.SubtractOne();

            MoneyInside       -= allocate;
            MoneyInTransaction = 0;
        }
Exemplo n.º 25
0
        public virtual void BuySnack(int position)
        {
            if (CanBuySnack(position) != string.Empty)
            {
                throw new InvalidOperationException();
            }
            //Slots.Single(x => x.Position == position).Quantity--;
            var slot = GetSlot(position);

            //if (slot.SnackPile.Price > MoneyInTransaction.Amount) throw new InvalidOperationException();
            //if (slot.SnackPile.Price > MoneyInTransaction) throw new InvalidOperationException();
            slot.SnackPile = slot.SnackPile.SubtractOne();

            //No longer needed the InsertMoney take care of it
            //MoneyInside += MoneyInTransaction;

            //MoneyInTransaction = None;
            Money change = MoneyInside.Allocate(MoneyInTransaction - slot.SnackPile.Price);

            //if (change.Amount < MoneyInTransaction - slot.SnackPile.Price) throw new InvalidOperationException();

            MoneyInside       -= change;
            MoneyInTransaction = 0;
        }
Exemplo n.º 26
0
        public void BuySnack(int position)
        {
            var slot = GetSlot(position);

            if (slot.SnackPile.Price > MoneyInTransaction)
            {
                throw new InvalidOperationException();
            }

            slot.SnackPile = slot.SnackPile.SubtractOne();

            var change = MoneyInside.Allocate(MoneyInTransaction - slot.SnackPile.Price);

            if (change.Amount < MoneyInTransaction - slot.SnackPile.Price)
            {
                throw new InvalidOperationException();
            }

            MoneyInside -= change;

            MoneyInTransaction = 0;

            AddDomainEvent(new SnackBought(slot.Position, slot.SnackPile.Quantity, slot.SnackPile.Snack.Name));
        }