Exemplo n.º 1
0
        public virtual void ApplyCoupon(Coupon coupon, Tutor tutor)
        {
            if (coupon.CanApplyCoupon())
            {
                var userCoupon = UserCoupon.SingleOrDefault(w => w.Tutor.Id == tutor.Id && w.UsedAmount < w.Coupon.AmountOfUsePerUser);
                if (userCoupon != null)
                {
                    throw new DuplicateRowException();
                }
                var p = new UserCoupon(this, coupon, tutor);
                if (!_userCoupon.Add(p))
                {
                    throw new DuplicateRowException();
                }
                AddEvent(new ApplyCouponEvent(p));
                //{
                //    _userCoupon.Remove(p);
                //    _userCoupon.Add(p);
                //}
            }
            //if (coupon.Expiration.GetValueOrDefault(DateTime.MaxValue) < DateTime.UtcNow)
            //{
            //    throw new ArgumentException("invalid coupon");
            //}

            //if (AmountOfUsers.HasValue && AmountOfUsers.Value <= _userCoupon.Count)
            //{
            //    throw new OverflowException();
            //}
        }
Exemplo n.º 2
0
 protected bool Equals(UserCoupon other)
 {
     return(Equals(User.Id, other.User.Id) &&
            Equals(Tutor.Id, other.Tutor.Id) &&
            Equals(Coupon.Id, other.Coupon.Id));
 }