protected void lbtnInsert_Click(object sender, EventArgs e) { pnlErr.Visible = false; lblErrorMess.Text = ""; try { cvEndDate.Enabled = false; if (!dpEndDate.IsEmpty) { cvEndDate.Enabled = true; Page.Validate(); } if (Page.IsValid) { int ruleID = 0; WithdrawalRuleDetails details = new WithdrawalRuleDetails(); details.RegularityValue = int.Parse(ddlRegularity.SelectedValue); details.CounterAccountID = int.Parse(ddlCounterAccount.SelectedValue); details.AccountID = AccountId; details.FirstDateWithdrawal = dpFirstDate.SelectedDate; details.EndDateWithdrawal = dpEndDate.SelectedDate; details.Amount = dbAmount.Value; if (pnlPandhouderPermission.Visible) details.PandhouderPermissionValue = cbPandhouderPermission.Checked; details.TransferDescription = txtTransferDescription.Text; details.DoNotChargeCommission = chkNoCharges.Checked; WithdrawalRuleEditAdapter.SaveWithdrawalRule(ref ruleID, details); //Response.Redirect("WithdrawalRule.aspx?ID=" + Convert.ToString(ruleID)); Response.Redirect("Account.aspx"); } } catch (Exception ex) { pnlErr.Visible = true; lblErrorMess.Text = Utility.GetCompleteExceptionMessage(ex); } }
public static void SaveWithdrawalRule(ref int ruleID, WithdrawalRuleDetails ruleDetails) { IDalSession session = NHSessionFactory.CreateSession(); IWithdrawalRule rule = null; ICustomerAccount acc = (ICustomerAccount)AccountMapper.GetAccount(session, ruleDetails.AccountID); ICounterAccount counterAcc = CounterAccountMapper.GetCounterAccount(session, ruleDetails.CounterAccountID); if (acc == null) throw new ApplicationException("Account can not be found."); if (ruleID != 0) { // Edit existing Rule rule = WithdrawalRuleMapper.GetWithdrawalRule(session, ruleID); if (rule == null) throw new ApplicationException("Rule can not be found."); checkDeactivateRule(rule, ruleDetails.EndDateWithdrawal, ruleDetails.IsActive); rule.CounterAccount = counterAcc; rule.TransferDescription = ruleDetails.TransferDescription; rule.DoNotChargeCommission = ruleDetails.DoNotChargeCommission; WithdrawalRuleMapper.Update(session, rule); } else { Money amount = null; WithdrawalRuleRegularity regularity = null; if (!(acc.Status == AccountStati.Active && acc.TradeableStatus == Tradeability.Tradeable)) throw new ApplicationException("It is not possible a withdrawal rule for an account that is not active or tradeable."); if (ruleDetails.Amount != 0) amount = new Money(ruleDetails.Amount, acc.AccountOwner.StichtingDetails.BaseCurrency); else throw new ApplicationException("Set Amount."); regularity = WithdrawalRuleMapper.GetWithdrawalRuleRegularity(session, (Regularities)ruleDetails.RegularityValue); // Create new Rule rule = new WithdrawalRule(amount, regularity, ruleDetails.FirstDateWithdrawal, counterAcc); rule.DoNotChargeCommission = ruleDetails.DoNotChargeCommission; if (Util.IsNotNullDate(ruleDetails.EndDateWithdrawal)) rule.EndDateWithdrawal = ruleDetails.EndDateWithdrawal; if (acc.PandHouder != null) { if (ruleDetails.PandhouderPermissionValue.HasValue && ruleDetails.PandhouderPermissionValue.Value) rule.PandhouderPermission = PandhouderPermissions.Yes; else throw new ApplicationException("Pandhouder Permission is needed."); } rule.TransferDescription = ruleDetails.TransferDescription; acc.WithdrawalRules.Add(rule); if (rule.Validate()) AccountMapper.Update(session, acc); } ruleID = rule.Key; session.Close(); }
protected void lbtnUpdate_Click(object sender, EventArgs e) { pnlErr.Visible = false; lblErrorMess.Text = ""; try { if (!dpEndDate.IsEmpty) cvEndDate.Enabled = true; Page.Validate(); if (Page.IsValid) { int ruleID = 0; if (hfRuleID.Value.Length > 0) ruleID = int.Parse(hfRuleID.Value); WithdrawalRuleDetails details = new WithdrawalRuleDetails(); details.EndDateWithdrawal = dpEndDate.SelectedDate; details.CounterAccountID = int.Parse(ddlCounterAccount.SelectedValue); details.AccountID = AccountId; details.IsActive = chkIsActive.Checked; details.DoNotChargeCommission = chkNoCharges.Checked; details.TransferDescription = txtTransferDescription.Text; WithdrawalRuleEditAdapter.SaveWithdrawalRule(ref ruleID, details); Response.Redirect("Account.aspx"); } } catch (Exception ex) { pnlErr.Visible = true; lblErrorMess.Text = Utility.GetCompleteExceptionMessage(ex); } }
public static WithdrawalRuleDetails GetWithdrawalRule(int ruleID) { IDalSession session = NHSessionFactory.CreateSession(); IWithdrawalRule rule = WithdrawalRuleMapper.GetWithdrawalRule(session, ruleID); WithdrawalRuleDetails ruleDetails = new WithdrawalRuleDetails(); ruleDetails.RegularityLabel = rule.Regularity.Description; ruleDetails.RegularityValue = (int)rule.Regularity.Key; if (rule.Account != null) ruleDetails.AccountNumber = rule.Account.Number; if (rule.CounterAccount != null) ruleDetails.CounterAccountID = rule.CounterAccount.Key; else ruleDetails.CounterAccountID = int.MinValue; if (Util.IsNotNullDate(rule.FirstDateWithdrawal)) ruleDetails.FirstDateWithdrawal = rule.FirstDateWithdrawal; else ruleDetails.FirstDateWithdrawal = DateTime.MinValue; if (Util.IsNotNullDate(rule.EndDateWithdrawal)) ruleDetails.EndDateWithdrawal = rule.EndDateWithdrawal; else ruleDetails.EndDateWithdrawal = DateTime.MinValue; ruleDetails.Amount = rule.Amount.Quantity; ruleDetails.PandhouderPermission = rule.PandhouderPermission.ToString(); ruleDetails.IsActive = rule.IsActive; ruleDetails.DoNotChargeCommission = rule.DoNotChargeCommission; ruleDetails.TransferDescription = rule.TransferDescription; session.Close(); return ruleDetails; }