Example #1
0
        protected internal void End(RentPoint rentPoint, DateTime endTime, decimal sum)
        {
            if (rentPoint == null)
            {
                throw new ArgumentNullException(nameof(rentPoint));
            }
            if (IsEnded)
            {
                throw new InvalidOperationException("Rent is already ended");
            }

            EndedAt      = endTime;
            EndRentPoint = rentPoint;
            EndRentPoint.CashBox.PutMoney(sum);
            Bike.Return(EndRentPoint);
            EndRentPoint.AddBike(Bike);
            if (StartRentPoint == EndRentPoint)
            {
                EndRentPoint.Safe.ReturnDeposit(Deposit);
            }
            else
            {
                if (Deposit.Type == DepositTypes.Passport)
                {
                    throw new InvalidOperationException("No such passport here");
                }

                EndRentPoint.CashBox.TakeMoney(((MoneyDeposit)Deposit).Sum);
                StartRentPoint.Safe.MoveMoneyToCashBox(StartRentPoint.CashBox, ((MoneyDeposit)Deposit).Sum);
            }
        }
Example #2
0
        public void MoveTo(RentPoint rentPoint)
        {
            if (!IsFree)
            {
                throw new InvalidOperationException("Bike is not free");
            }

            if (rentPoint == null)
            {
                throw new ArgumentNullException(nameof(rentPoint));
            }

            if (rentPoint == RentPoint)
            {
                this.LockOnRentPoint(rentPoint);
                rentPoint.AddBike(this);
                return;
            }
            RentPoint?.RemoveBike(this);

            rentPoint.AddBike(this);

            RentPoint = rentPoint;
        }
Example #3
0
        public void MoveTo(RentPoint rentPoint)
        {
            if (rentPoint == null)
            {
                throw new ArgumentNullException(nameof(rentPoint));
            }

            if (rentPoint == RentPoint)
            {
                return;
            }

            RentPoint?.RemoveBike(this);

            rentPoint.AddBike(this);

            RentPoint = rentPoint;
        }