public GiftCertificate GetGiftCertificateById(long giftCertificateId)
        {
            IGiftCertificateRepository giftCertificateRepository = new GiftCertificateRepository();
            var giftCertificate = giftCertificateRepository.GetById(giftCertificateId);

            if (giftCertificate != null)
            {
                //TODO Need to check the table tblGiftCertificatePayment for pulling the exhausted amount.
                //var masterDal = new MasterDAL();
                //giftCertificate.Amount = masterDal.GetExhaustedGiftCertificateAmount(giftCertificate.Id);
                giftCertificate.Amount = giftCertificateRepository.GetAmountUsedonGiftCertificate(giftCertificate.Id);
                if (giftCertificate.BalanceAmount > 0 &&
                    ((giftCertificate.ExpirationDate.HasValue && giftCertificate.ExpirationDate >= DateTime.Today) || !giftCertificate.ExpirationDate.HasValue))
                {
                    return(giftCertificate);
                }

                if (giftCertificate.ExpirationDate.HasValue && giftCertificate.ExpirationDate < DateTime.Today)
                {
                    throw new ObjectDeactivatedException <GiftCertificate>();
                }

                throw new InvalidOperationException(
                          "There is no amount left in the given gift certificate, please use another mode to pay.");
            }
            throw new InvalidOperationException("The given gift certificate is not valid.");
        }
Example #2
0
    public void CreateCertificate()
    {
        //Do whatever needs to create a certificate.
        GiftCertificateRepository gcRepo = new GiftCertificateRepository();
        GiftCertificateModel      gc     = gcRepo.CreateNew();

        gc.Amount         = 10.00M;
        gc.ExpirationDate = DateTime.Today.AddMonths(12);
        gc.Notes          = "Test GC";
        gcRepo.Save(gc);
    }
        public GiftCertificate GetGiftCertificate(long giftCertificateId)
        {
            IGiftCertificateRepository giftCertificateRepository = new GiftCertificateRepository();
            var giftCertificate = giftCertificateRepository.GetById(giftCertificateId);

            if (giftCertificate != null)
            {
                IUniqueItemRepository <GiftCertificatePayment> uniqueItemRepository =
                    new GiftCertificatePaymentRepository();

                GiftCertificatePayment giftCertificatePayment = null;
                try
                {
                    giftCertificatePayment = uniqueItemRepository.GetById(giftCertificateId);
                }
                catch (ObjectNotFoundInPersistenceException <GiftCertificatePayment> )
                { }

                giftCertificate.Amount = giftCertificatePayment == null ? 0 : giftCertificatePayment.Amount;

                if (giftCertificate.BalanceAmount > 0 &&
                    ((giftCertificate.ExpirationDate.HasValue && giftCertificate.ExpirationDate >= DateTime.Today) || !giftCertificate.ExpirationDate.HasValue))
                {
                    return(giftCertificate);
                }

                if (giftCertificate.ExpirationDate.HasValue && giftCertificate.ExpirationDate < DateTime.Today)
                {
                    throw new ObjectDeactivatedException <GiftCertificate>();
                }

                throw new InvalidOperationException(
                          "There is no amount left in the given gift certificate, please use another mode to pay.");
            }
            throw new InvalidOperationException("The given gift certificate is not valid.");
        }