/// <summary>
 /// this method deletes a FinancierOperation
 /// </summary>
 /// <param name="entity"></param>
 public void DeleteFinancierOperation(FinancierOperation entity)
 {
     DbContext.FinancierOperations.DeleteOnSubmit(entity);
     DbContext.SubmitChanges();
 }
 /// <summary>
 /// this method inserts a FinancierOperation
 /// </summary>
 /// <param name="entity"></param>
 public void InsertFinancierOperation(FinancierOperation entity)
 {
     DbContext.FinancierOperations.InsertOnSubmit(entity);
     DbContext.SubmitChanges();
 }
        ///// <summary>
        ///// This method return a financierOperation by specified paymentMethod
        ///// </summary>
        ///// <param name="paymentMethodId"></param>
        ///// <returns></returns>
        //public FinancierOperation GetFinancierOperation(Int32 companyId, Int32 paymentMethodId)
        //{
        //    return DbContext.FinancierOperations.Where(x => x.CompanyId == companyId && x.PaymentMethodId == paymentMethodId).FirstOrDefault();
        //}

        /// <summary>
        /// this method updates a FinancierOperation
        /// </summary>
        /// <param name="original_entity"></param>
        /// <param name="entity"></param>
        public void UpdateFinancierOperation(FinancierOperation original_entity, FinancierOperation entity)
        {
            original_entity.CopyPropertiesFrom(entity);
            DbContext.SubmitChanges();
        }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        var payment = AccountManager.GetPaymentMethod(Convert.ToInt32(cboPaymentMethod.SelectedValue));

        if (payment != null)
            if (String.IsNullOrEmpty(txtMembershipNUmber.Text) || String.IsNullOrEmpty(txtOperationNumber.Text))
                if (payment.PaymentMethodId == PaymentMethod.MasterCard || payment.PaymentMethodId == PaymentMethod.Visa)
                {
                    ShowError("O numero de afiliação e código de operação são obrigatórios!");
                    return;
                }

        var financierOperation = new FinancierOperation();

        if (IsLoaded)
        {
            financierOperation.CopyPropertiesFrom(OriginalFinancierOperation);

            if (OriginalFinancierOperation.PaymentMethodId != Convert.ToInt32(cboPaymentMethod.SelectedValue) && VerifyUniquePaymentMethod())
            {
                ShowError("Já existe uma operação financeira com o método de pagamento fornecido!");
                return;
            }
        }

        financierOperation.CompanyId = Company.CompanyId;
        financierOperation.AdminTax = Convert.ToDecimal(ucCurrFieldAdminTax.CurrencyValue);
        financierOperation.AdminTaxUnit = Convert.ToDecimal(ucCurrFieldAdminTaxUnit.CurrencyValue);
        financierOperation.Discount = Convert.ToDecimal(ucCurrFieldDiscount.CurrencyValue);
        financierOperation.PaymentMethodId = Convert.ToInt32(cboPaymentMethod.SelectedValue);
        financierOperation.MembershipNumber = txtMembershipNUmber.Text;
        financierOperation.OperationNumber = txtOperationNumber.Text;
        financierOperation.AccountId = Convert.ToInt32(cboAccount.SelectedValue);


        if (IsLoaded)
            AccountManager.UpdateFinancierOperation(OriginalFinancierOperation, financierOperation);
        else
        {
            if (VerifyUniquePaymentMethod())
            {
                ShowError("Já existe uma operação financeira com o método de pagamento fornecido!");
                return;
            }

            AccountManager.InsertFinancierOperation(financierOperation);
            Page.ViewState["FinancierOperationId"] = financierOperation.FinancierOperationId;
            pnlFinancierCondition.Visible = true;
            return;
        }
        //if (financierOperation.PaymentProvider != null)
        //  financierOperation.PaymentProvider.SaveConfiguration(financierOperation.MembershipNumber, financierOperation.OperationNumber);

        Response.Redirect("~/InfoControl/Accounting/FinancierOperations.aspx");
    }