Example #1
0
        public bool PayForDelivery(string userName, long billId)
        {
            Bill bill = _billRepository.FindByIdAndIsDeliveryPaidFalse(billId);

            if (bill == null)
            {
                throw new DeliveryAlreadyPaidException();
            }
            User user = _userRepository.FindByIdAndUserMoneyInCentsGreaterThanEqual(userName, bill.CostInCents);

            if (user == null)
            {
                throw new NotEnoughMoneyException();
            }

            user.UserMoneyInCents = (user.UserMoneyInCents - bill.CostInCents);
            bill.IsDeliveryPaid   = true;
            bill.DateOfPay        = DateTime.Now;
            _userRepository.Save();
            _billRepository.Save();
            return(true);
        }