Пример #1
0
        private void btnAddConfig_Click(object sender, EventArgs e)
        {
            int    idUser             = _userController.ListAllAsNotracking()[cmbUser.SelectedIndex].Id;
            string idPaymentMechanism = _paymentWays.ListALL()[cmbPaymentMechanism.SelectedIndex].Id;

            ConfigCurrentAccount configAccount = _configAccountUserController.ListForUserIdPaymentId(idUser, idPaymentMechanism);

            if (configAccount == null)
            {
                configAccount = new ConfigCurrentAccount();
                configAccount.CurrentAccountId   = _currentAccountController.ListALLAsNoTracking()[cmbAccounts.SelectedIndex].Id;
                configAccount.PaymentMechanismId = idPaymentMechanism;
                configAccount.UserId             = idUser;
                _configAccountUserController.insert(configAccount);

                _configAccountUserController.Dispose();

                _configAccountUserController = new ConfigCurrentAccountController();
            }

            updateGrid();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            ConfigCurrentAccount configAccount = new ConfigCurrentAccount()
            {
                CurrentAccountId   = _accountSystemController.ListALL()[cmbAccount.SelectedIndex].Id,
                PaymentMechanismId = _paymentController.ListALL()[cbPaymentMechanism.SelectedIndex].Id,
            };

            ConfigCurrentAccount existsConfig = _configAccountPayment.getForPaymentId(_paymentController.ListALL()[cbPaymentMechanism.SelectedIndex].Id);

            if (existsConfig == null)
            {
                _configAccountPayment.insert(configAccount);
            }
            else
            {
                DialogResult msbR = MessageBox.Show("Já tem a conta: " + existsConfig.CurrentAccount.Descricao + " para essa forma de pagamento, Deseja substituir?", "Substituir Conta para forma de pagamento", MessageBoxButtons.OK, MessageBoxIcon.Question);
                if (msbR == DialogResult.OK)
                {
                    existsConfig.CurrentAccountId = _accountSystemController.ListALL()[cmbAccount.SelectedIndex].Id;
                    _configAccountPayment.update(existsConfig);
                }
            }
        }