/// <summary>
        /// 消费次卡产品
        /// </summary>
        /// <param name="tutorId">教师Id</param>
        /// <param name="timesCardMemberCardId">次卡产品Id</param>
        void IStudioService.TakeMemberProduct(Guid tutorId, Guid timesCardMemberCardId)
        {
            var memberCard = _memberCardMgr.GetById(timesCardMemberCardId);

            if (memberCard == null)
            {
                throw new MemberCardNotExistException(string.Format("会员卡[{0}]不存在!", timesCardMemberCardId));
            }

            var tutor = _tutorMgr.GetById(tutorId);

            if (tutor == null)
            {
                throw new TutorNotExistException("教师不存在!");
            }

            using (TransactionScope scope = new TransactionScope())
            {
                Consumption consumption = (memberCard as TimesCardMemberCard).Consume(tutor);

                _consumptionMgr.Save(consumption);
                _memberCardMgr.Save(memberCard);

                scope.Complete();
            }
        }
Example #2
0
        public void Sell(Guid tutorId, Guid productId, string customer, string phoneNumber)
        {
            var      tutor   = _tutorMgr.GetById(tutorId);
            var      product = _productMgr.Get(productId);
            Purchase purchase;
            Member   member = null;

            if (product is MemberProduct)
            {
                member = _memberMgr.Get(phoneNumber);
                if (member == null)
                {
                    throw new MemberNotExistException();
                }
                purchase = tutor.Sell((MemberProduct)product, member);
                _memberMgr.Modify(member);
                foreach (var balance in member.Balances)
                {
                    _balanceMgr.Modify(balance);
                }
            }
            else
            {
                purchase = tutor.Sell((OneTimeExperience)product);
            }

            purchase.GenerateNewIdentity();
            _purchaseRepository.Add(purchase);
            _purchaseRepository.UnitOfWork.Commit();
        }