/// <summary> /// Checks discount limitations for customer /// </summary> /// <param name="customer">Customer</param> /// <returns>Value indicating whether discount can be used</returns> public bool CheckDiscountLimitations(Customer customer) { switch (this.DiscountLimitation) { case DiscountLimitationEnum.Unlimited: { return(true); } case DiscountLimitationEnum.OneTimeOnly: { var usageHistory = DiscountManager.GetAllDiscountUsageHistoryEntries(this.DiscountId, null, null); return(usageHistory.Count < 1); } case DiscountLimitationEnum.NTimesOnly: { var usageHistory = DiscountManager.GetAllDiscountUsageHistoryEntries(this.DiscountId, null, null); return(usageHistory.Count < this.LimitationTimes); } case DiscountLimitationEnum.OneTimePerCustomer: { if (customer != null) { var usageHistory = DiscountManager.GetAllDiscountUsageHistoryEntries(this.DiscountId, customer.CustomerId, null); return(usageHistory.Count < 1); } else { return(false); } } case DiscountLimitationEnum.NTimesPerCustomer: { if (customer != null) { var usageHistory = DiscountManager.GetAllDiscountUsageHistoryEntries(this.DiscountId, customer.CustomerId, null); return(usageHistory.Count < this.LimitationTimes); } else { return(false); } } default: break; } return(false); }
/// <summary> /// Checks discount limitations for customer /// </summary> /// <param name="customer">Customer</param> /// <returns>Value indicating whether discount can be used</returns> public bool CheckDiscountLimitations(Customer customer) { switch (this.DiscountLimitation) { case DiscountLimitationEnum.Unlimited: { return(true); } break; case DiscountLimitationEnum.OneTimeOnly: { DiscountUsageHistoryCollection usageHistory = DiscountManager.GetAllDiscountUsageHistoryEntries(this.DiscountId, null, null); return(usageHistory.Count < 1); } break; case DiscountLimitationEnum.OneTimePerCustomer: { if (customer != null) { DiscountUsageHistoryCollection usageHistory = DiscountManager.GetAllDiscountUsageHistoryEntries(this.DiscountId, customer.CustomerId, null); return(usageHistory.Count < 1); } else { //TODO decide what to return when customer is not registered; //return true; return(false); } } break; default: break; } return(false); }