/// <summary>
        /// Save Transaction Entity
        /// </summary>
        /// <param name="item">Entity to save</param>
        /// <param name="errorMessage">Error Message</param>
        /// <returns>return true if save successfully, else return false</returns>
        public static bool Save(Transaction item, out string errorMessage)
        {
            bool isValid = Validate(item, out errorMessage);

            if (isValid)
            {
                TransactionDao.Save(item);
            }

            return isValid;
        }
 /// <summary>
 /// Saves a Transaction to the data store.
 /// </summary>
 /// <param name="item">The item to save</param>
 public static void Save(Transaction item)
 {
     if (item.IsItemModified)
     {
         if (item.TransactionId == null)
         {
             item.TransactionId = Insert(item);
         }
         else
         {
             Update(item);
         }
     }
 }
        public bool Save(out string errorMessage)
        {
            Event eventEntity = new Event();
            Transaction transaction = new Transaction();

            if (UserControlMode == EnumUserControlMode.Edit && EventId.HasValue)
            {
                eventEntity = EventManager.Load(EventId.Value);
                transaction = TransactionManager.LoadByEvent(EventId.Value);
            }

            LoadEventFromForm(eventEntity);
            LoadTransactionFromForm(transaction);

            string eventError,  transactionError = string.Empty;

            if (EventManager.Validate(eventEntity, out eventError) &&
                TransactionManager.Validate(transaction, out transactionError))
            {
                EventManager.Save(eventEntity, out errorMessage);

                if (eventEntity.EventId.HasValue)
                {
                    transaction.EventId = eventEntity.EventId.Value;

                    TransactionManager.Save(transaction, out errorMessage);

                    TransactionId = transaction.TransactionId;
                }
            }
            else
            {
                errorMessage = string.Format("{0}{1}{2}", eventError, StringMethods.BreakTag, transactionError);
            }

            return errorMessage.IsNullOrWhiteSpace();
        }
 /// <summary>
 /// Updates a Transaction
 /// </summary>
 /// <param name="item">The Transaction item to save</param>
 private static void Update(Transaction item)
 {
     List<SqlParameter> parameters
         = new List<SqlParameter>
             {
                 new SqlParameter("@TransactionId", item.TransactionId),
                 new SqlParameter("@EventId", item.EventId),
                 new SqlParameter("@UserId", item.UserId),
                 new SqlParameter("@FeeTypeId", item.FeeType),
                 new SqlParameter("@FeeAdjustmentId", item.FeeAdjustment),
                 new SqlParameter("@Fee", item.Fee),
                 new SqlParameter("@CreditCardNumber", item.CreditCardNumber),
                 new SqlParameter("@CreditCardTypeId", item.CreditCardType),
                 new SqlParameter("@ExpirationDate", item.ExpirationDate),
                 new SqlParameter("@CCV", item.CCV),
                 new SqlParameter("@BillingAddress", item.BillingAddress),
                 new SqlParameter("@BillingCity", item.BillingCity),
                 new SqlParameter("@BillingState", item.BillingState),
                 new SqlParameter("@BillingZip", item.BillingZip),
                 new SqlParameter("@TransactionDate", item.TransactionDate)
             };
     DataManager.ExecuteProcedure(ConferencePlusConnectionString, "Transaction_Update", parameters);
 }
 private void LoadTransactionFromForm(Transaction transaction)
 {
     transaction.BillingAddress = txtBillingAddress.Text.TrimSafely();
     transaction.BillingCity = txtCity.Text.TrimSafely();
     transaction.BillingState = rcbStates.SelectedValue;
     transaction.BillingZip = txtZip.Text.TrimSafely();
     transaction.CCV = txtCCV.Value.GetValueOrDefault().ToInt();
     transaction.CreditCardNumber = txtCreditCardNumber.Text.TrimSafely();
     transaction.CreditCardType = EnumerationsHelper.ConvertFromString<EnumCreditCardType>(rcbCreditCardType.SelectedValue);
     transaction.ExpirationDate = rdpExpirationDate.SelectedDate.GetValueOrDefault();
     transaction.Fee = txtFee.Value.GetValueOrDefault().ToDecimal();
     transaction.FeeAdjustment = lblFeeAdjustment.Text.HasValue()
         ? EnumerationsHelper.ConvertFromString<EnumFeeAdjustment>(lblFeeAdjustment.Text)
         : (EnumFeeAdjustment?) null;
     transaction.FeeType = EnumerationsHelper.ConvertFromString<EnumFeeType>(rblFeeType.SelectedValue);
     transaction.TransactionDate = DateTime.Now;
     transaction.UserId = UserId;
 }
        /// <summary>
        /// Validate Transaction Entity
        /// </summary>
        /// <param name="item">Entity to validate</param>
        /// <param name="errorMessage">error message if vlidation failed</param>
        /// <returns>return true if entity passes validation logic, else return false</returns>
        public static bool Validate(Transaction item, out string errorMessage)
        {
            StringBuilder builder = new StringBuilder();

            PaymentInfo info = TypeMapper<PaymentInfo>.Map(item);

            if (!PaymentInfoManager.Validate(info, out errorMessage))
            {
                builder.AppendHtmlLine(errorMessage);
            }

            if (item.Fee == default(decimal))
            {
                builder.AppendHtmlLine("*Fee is required");
            }

            if (item.FeeAdjustment == EnumFeeAdjustment.None)
            {
                builder.AppendHtmlLine("*Fee adjustment is required");
            }

            if (item.FeeType == EnumFeeType.None)
            {
                builder.AppendHtmlLine("*Fee type is required");
            }

            if (!item.TransactionDate.IsValidWithSqlDateStandards())
            {
                builder.AppendHtmlLine("*Transaction date is required");
            }

            if (item.UserId == default(Guid))
            {
                builder.AppendHtmlLine("*User Id is required");
            }

            errorMessage = builder.ToString();

            return errorMessage.IsNullOrWhiteSpace();
        }