Ejemplo n.º 1
0
        private int SaveGiftCertificate()
        {
            if (Page.IsValid)
            {
                IGiftCertKeyProvider gckProvider = AbleContext.Container.Resolve <IGiftCertKeyProvider>();
                _GiftCertificate.Name = Name.Text;
                decimal newBalance = AlwaysConvert.ToDecimal(Balance.Text);

                if (newBalance != _GiftCertificate.Balance)
                {
                    _GiftCertificate.AddBalanceUpdatedTransaction(_GiftCertificate.Balance, newBalance);
                    _GiftCertificate.Balance = newBalance;
                }

                DateTime newDate = ExpireDate.SelectedEndDate;
                DateTime oldDate = _GiftCertificate.ExpirationDate.HasValue ? _GiftCertificate.ExpirationDate.Value : DateTime.MinValue;
                if (!oldDate.Equals(newDate))
                {
                    _GiftCertificate.AddExpiryUpdatedTransaction(oldDate, newDate);
                    _GiftCertificate.ExpirationDate = ExpireDate.NullableSelectedEndDate;
                }

                if (GenerateSerialNumber.Checked)
                {
                    if (string.IsNullOrEmpty(_GiftCertificate.SerialNumber))
                    {
                        _GiftCertificate.AddActivatedTransaction();
                    }
                    _GiftCertificate.SerialNumber = gckProvider.GenerateGiftCertificateKey();
                }
                _GiftCertificate.Save();
                return(_GiftCertificate.Id);
            }
            return(0);
        }
        protected void GiftCertificatesGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int             GiftCertificateId = AlwaysConvert.ToInt(e.CommandArgument);
            GiftCertificate gc = GiftCertificateDataSource.Load(GiftCertificateId);

            if (gc == null)
            {
                return;
            }
            IGiftCertKeyProvider provider = AbleContext.Container.Resolve <IGiftCertKeyProvider>();

            if (e.CommandName.Equals("Generate"))
            {
                gc.SerialNumber = provider.GenerateGiftCertificateKey();
                gc.AddActivatedTransaction();
                gc.Save();
                GiftCertificatesGrid.DataBind();
            }
            else if (e.CommandName.Equals("Deactivate"))
            {
                gc.SerialNumber = "";
                gc.AddDeactivatedTransaction();
                gc.Save();
                GiftCertificatesGrid.DataBind();
            }
        }
        private int SaveGiftCertificate()
        {
            if (Page.IsValid)
            {
                // VALIDATE IF A PROPER EXPIRE DATE IS SELECTED
                if (ExpireDate.SelectedEndDate != DateTime.MinValue && DateTime.Compare(ExpireDate.SelectedEndDate, LocaleHelper.LocalNow) < 0)
                {
                    CustomValidator dateValidator = new CustomValidator();
                    dateValidator.ControlToValidate = "Name"; // THIS SHOULD BE "ExpireDate" CONTROL, BUT THAT CANNOT BE VALIDATED
                    dateValidator.Text         = "*";
                    dateValidator.ErrorMessage = "Expiration date cannot be in the past.";
                    dateValidator.IsValid      = false;
                    phExpirationValidator.Controls.Add(dateValidator);
                    return(0);
                }
                GiftCertificate _GiftCertificate = new GiftCertificate();
                _GiftCertificate.Name           = Name.Text;
                _GiftCertificate.Store          = AbleContext.Current.Store;
                _GiftCertificate.CreatedBy      = AbleContext.Current.UserId;
                _GiftCertificate.Balance        = AlwaysConvert.ToDecimal(Balance.Text);
                _GiftCertificate.ExpirationDate = ExpireDate.NullableSelectedEndDate;
                _GiftCertificate.CreateDate     = LocaleHelper.LocalNow;
                _GiftCertificate.AddCreatedManuallyTransaction();

                if (Activated.Checked)
                {
                    IGiftCertKeyProvider gckProvider = AbleContext.Container.Resolve <IGiftCertKeyProvider>();
                    _GiftCertificate.SerialNumber = gckProvider.GenerateGiftCertificateKey();
                    _GiftCertificate.AddActivatedTransaction();
                }
                else
                {
                    _GiftCertificate.SerialNumber = "";
                }

                _GiftCertificate.Save();
                return(_GiftCertificate.Id);
            }
            return(0);
        }