Ejemplo n.º 1
0
        public void TakeTimesCard(Guid tutorId, Guid memberProductId, string memberPhoneNumber)
        {
            var member = _memberMgr.Get(memberPhoneNumber);

            if (member == null)
            {
                throw new MemberNotExistException();
            }
            var balance     = new Balance();
            var consumption = member.Consume(memberProductId, tutorId, out balance);

            _consumptionRepository.Add(consumption);
            _balanceMgr.Modify(balance);
        }
        /// <summary>
        /// 保存消费记录
        /// </summary>
        public void Save(Consumption consumption)
        {
            List <ValidationResult> results = new List <ValidationResult>();
            bool isValid = Validator.TryValidateObject(consumption,
                                                       new ValidationContext(consumption),
                                                       results);

            if (!isValid)
            {
                throw new ArgumentException("消费数据不合法!");
            }

            if (consumption.IsTransient())
            {
                consumption.GenerateNewIdentity();
                _consumptionRepository.Add(consumption);
            }
            else
            {
                _consumptionRepository.Modify(consumption);
            }

            _consumptionRepository.UnitOfWork.Commit();
        }