Exemplo n.º 1
0
        void btnSave_Click(object sender, EventArgs e)
        {
            ImportedGiftCert cert = ImportedGiftCert.GetBy(lblCode.Text);

            if (cert != null)
            {
                cert.is_used   = chkRedeemed.Checked ? "Y" : "N";
                cert.code      = long.Parse(lblCode.Text.Trim());
                cert.amount    = decimal.Parse(txtAmount.Text.Trim());
                cert.date_used = txtDateUsed.Text;
                //cert.used_by = txtUsedBy.Text;
                cert.Save();

                lblFBImpCert.Text = "Gift certificate has been saved.";
            }
            else
            {
                lblFBImpCert.Text = "Gift certificate not found.";
            }

            pnlImpCertEdit.Visible = false;
        }
        protected override void SaveForm()
        {
            try
            {
                hccLedger ledger = new hccLedger
                {
                    AspNetUserID      = CurrentAspNetUserId,
                    CreatedBy         = (Guid)Helpers.LoggedUser.ProviderUserKey,
                    CreatedDate       = DateTime.Now,
                    Description       = txtXactDesc.Text.Trim(),
                    TransactionTypeID = int.Parse(ddlXactTypes.SelectedValue)
                };

                if (ledger.TransactionType == Enums.LedgerTransactionType.RedeemGiftCertificate)
                {
                    hccCartItem gcCartItem   = hccCartItem.GetGiftBy(txtXactGCRedeem.Text);
                    bool        updateLedger = false;

                    if (gcCartItem != null)
                    {
                        gcCartItem.Gift_RedeemedBy   = CurrentAspNetUserId;
                        gcCartItem.Gift_RedeemedDate = DateTime.Now;
                        gcCartItem.Save();
                        updateLedger = true;
                    }
                    else
                    {
                        ImportedGiftCert cert = ImportedGiftCert.GetBy(txtXactGCRedeem.Text);
                        if (cert != null)
                        {
                            cert.used_by   = gcCartItem.UserProfileID;
                            cert.date_used = DateTime.Now.ToString();
                            cert.is_used   = "Y";
                            cert.Save();
                            updateLedger = true;
                        }
                    }

                    if (updateLedger)
                    {
                        ledger.TotalAmount    = gcCartItem.ItemPrice;
                        ledger.GiftRedeemCode = gcCartItem.Gift_RedeemCode;
                        ledger.Description    = "Gift Certificate Redemption: " + ledger.GiftRedeemCode;
                    }
                    else
                    {
                        ledger = null;
                    }
                }
                else
                {
                    ledger.TotalAmount = decimal.Parse(txtXactAmount.Text.Trim());
                }

                hccUserProfile profile = hccUserProfile.GetParentProfileBy(CurrentAspNetUserId);

                if (profile != null)
                {
                    // check against last entry for duplicate
                    hccLedger lastEntry        = hccLedger.GetByMembershipID(profile.MembershipID, null).OrderByDescending(a => a.CreatedDate).FirstOrDefault();
                    bool      isDuplicateEntry = false;

                    if (ledger != null)
                    {
                        if (lastEntry != null &&
                            ledger.CreatedBy == lastEntry.CreatedBy &&
                            ledger.CreditFromBalance == lastEntry.CreditFromBalance &&
                            ledger.Description == lastEntry.Description &&
                            ledger.PaymentDue == lastEntry.PaymentDue &&
                            ledger.TransactionTypeID == lastEntry.TransactionTypeID &&
                            ledger.TotalAmount == lastEntry.TotalAmount)
                        {
                            isDuplicateEntry = true;
                        }

                        if (!isDuplicateEntry)
                        {
                            switch (ledger.TransactionType)
                            {
                            case Enums.LedgerTransactionType.HCCAccountCredit:
                            case Enums.LedgerTransactionType.RedeemGiftCertificate:
                                profile.AccountBalance = profile.AccountBalance + ledger.TotalAmount;
                                break;

                            case Enums.LedgerTransactionType.HCCAccountDebit:
                                profile.AccountBalance = profile.AccountBalance - ledger.TotalAmount;
                                break;

                            case Enums.LedgerTransactionType.Purchase:
                            case Enums.LedgerTransactionType.Return:
                                ledger.PaymentDue = ledger.TotalAmount;
                                break;

                            default: break;
                            }

                            ledger.PostBalance = profile.AccountBalance;
                            ledger.Save();
                            profile.Save();

                            this.Bind();
                            OnSaved(new ControlSavedEventArgs(CurrentAspNetUserId));

                            txtXactAmount.Text   = string.Empty;
                            txtXactDesc.Text     = string.Empty;
                            txtXactGCRedeem.Text = string.Empty;
                            ddlXactTypes.ClearSelection();
                        }
                        else
                        {
                            lblXactFeedback.Text = "This appears to be a duplicate transaction. If it is not a duplicate, please provide a comment to differentiate this transaction from the last.";
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }