Exemplo n.º 1
0
        /// <summary>
        /// Is gift voucher valid
        /// </summary>
        /// <param name="giftVoucher">Gift voucher</param>
        /// <returns>Result</returns>
        public static bool IsGiftVoucherValid(this GiftVoucher giftVoucher, Currency currency)
        {
            if (!giftVoucher.IsGiftVoucherActivated)
            {
                return(false);
            }

            if (giftVoucher.CurrencyCode != currency.CurrencyCode)
            {
                return(false);
            }

            if (giftVoucher.ValidTo.HasValue && giftVoucher.ValidTo.Value <= System.DateTime.UtcNow)
            {
                return(false);
            }

            decimal remainingAmount = giftVoucher.GetGiftVoucherRemainingAmount();

            if (remainingAmount > decimal.Zero)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a gift voucher remaining amount
        /// </summary>
        /// <returns>Gift voucher remaining amount</returns>
        public static decimal GetGiftVoucherRemainingAmount(this GiftVoucher giftVoucher)
        {
            decimal result = giftVoucher.Amount;

            foreach (var gcuh in giftVoucher.GiftVoucherUsageHistory)
            {
                result -= gcuh.UsedValue;
            }

            if (result < decimal.Zero)
            {
                result = decimal.Zero;
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a gift voucher remaining amount
        /// </summary>
        /// <returns>Gift voucher remaining amount</returns>
        public static double GetGiftVoucherRemainingAmount(this GiftVoucher giftVoucher)
        {
            double result = giftVoucher.Amount;

            foreach (var gcuh in giftVoucher.GiftVoucherUsageHistory)
            {
                result -= gcuh.UsedValue;
            }

            if (result < 0)
            {
                result = 0;
            }

            return(result);
        }