/// <summary> /// Removes a LoanBracket from the list of Loan Brackets in /// this Financial Institution /// </summary> /// <param name="loanBracket">LoanBracket to be Removed</param> public virtual void RemoveLoanBracket(LoanBracket loanBracket) { LoanBrackets.Remove (loanBracket); }
/// <summary> /// Adds a new LoanBracket to the list of Loan Brackets in /// this Financial Institution /// </summary> /// <param name="loanBracket">LoanBracket to be added</param> public virtual void AddLoanBracket(LoanBracket loanBracket) { loanBracket.FinancialInstitution = this; LoanBrackets.Add (loanBracket); }
/// <summary> /// Adds a list of Loan Parameters to the Loan Bracket /// </summary> /// <param name="loanBracketToUpdate">loanBracketToUpdate</param> /// <param name="selectedLoanParameterIds">selectedLoanParameterIds</param> public void AddParametersToLoanBracket(LoanBracket loanBracketToUpdate, IList<int> selectedLoanParameterIds) { try { ILoanParameterDAO loanParameterDAO = _daoFactory.GetLoanParameterDAO (); //If the client already exists then we won´t worry about it. foreach (LoanParameter loanParameter in loanBracketToUpdate.LoanParameters) { if (selectedLoanParameterIds.Contains (loanParameter.Id)) selectedLoanParameterIds.Remove (loanParameter.Id); } //TODO: Perhaps I should let them know that the Loan Bracket // laready contains the Loan PArameter the wish to add?? //Make sure it is not empty. if (selectedLoanParameterIds.Count > 0) { foreach (int selectedId in selectedLoanParameterIds) { LoanParameter loanParameter = loanParameterDAO.FindById (selectedId); if (loanParameter != null) { //Look throught the list of parameters already contained in the bracket. //and verify that there is no parameter with the same type of loan foreach (LoanParameter exisitngParam in loanBracketToUpdate.LoanParameters) { if (exisitngParam.LoanType == loanParameter.LoanType) { throw new ZiblerBusinessComponentsException ( Resources.SystemParametersOperationsMsgLoanTypeFromParameterToAssociateMustBeUnique); } } //No exception was thrown then add the parameter to the list. loanBracketToUpdate.AddLoanParameter (loanParameter); } else { throw new ZiblerBusinessComponentsException ( Resources.SystemParametersOperationsMsgLoanParameterNotExists); } } } } /* If the exception was thrown here, just pass it up */ catch (ZiblerBusinessComponentsException ex) { throw; } /* Catch any Data Layer or other exception and throw an unkown exception */ catch (Exception ex) { ZiblerBusinessComponentsUnknownException exc = new ZiblerBusinessComponentsUnknownException (ex); /* Throw the new exception */ throw exc; } }
/// <summary> /// Creates a new Loan Bracket for the given financial institution /// </summary> /// <param name="financialInstitution">financialInstitution</param> /// <param name="user nam">user nam</param> /// <param name="loanBracket">loanBracket to be created</param> public void CreateNewLoanBracket(string financialInstitutionName, string userName, LoanBracket loanBracket) { try { IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO (); //Get all existing Loan Brackets FinancialInstitution financialInstitution = financialInstitutionDAO.GetFinancialInstitutionByName ( financialInstitutionName); //Make sure the name is not repeated. foreach (LoanBracket existingBracket in financialInstitution.LoanBrackets) { if (existingBracket.Name == loanBracket.Name) throw new ZiblerBusinessComponentsException ( Resources.SystemParametersOperationMsgLoanBracketExists); } if (financialInstitution.LoanBrackets.IsEmpty) { //Simply add the new Loan bracket since there is no other brackets. financialInstitution.AddLoanBracket (loanBracket); } else { IList<LoanBracket> orderedList = new List<LoanBracket> (); //Copy the list to a structure that will make it easier to work with. foreach (LoanBracket existingLoanBracket in financialInstitution.LoanBrackets) { orderedList.Add (existingLoanBracket); } // Sorting: Bubble Sort for (int i = orderedList.Count - 1; i >= 0; i--) { for (int j = 1; j <= i; j++) { if (orderedList[j - 1].MinimumAmount > orderedList[j].MinimumAmount) { LoanBracket temp = orderedList[j - 1]; orderedList[j - 1] = orderedList[j]; orderedList[j] = temp; } } } bool reArranged = false; for (int i = 0; i < orderedList.Count; i++) { LoanBracket currentItem = orderedList[i]; if (currentItem.MaximumAmount + 1 == loanBracket.MinimumAmount) { //Start recalculating the max and min amounts. for (int j = i + 1; j < orderedList.Count; j++) { decimal range = 0.0m; //If it is the first one. if (j == i + 1) { range = orderedList[j].MaximumAmount - orderedList[j].MinimumAmount; orderedList[j].MinimumAmount = loanBracket.MaximumAmount + 1; orderedList[j].MaximumAmount = orderedList[j].MinimumAmount + range; } else { range = orderedList[j].MaximumAmount - orderedList[j].MinimumAmount; orderedList[j].MinimumAmount = orderedList[j - 1].MaximumAmount + 1; orderedList[j].MaximumAmount = orderedList[j].MinimumAmount + range; } } //We found the spot, and we have recalculated the amounts, //thus break from the loop. //Indicate we successfully added reArranged = true; break; } if (currentItem.MinimumAmount - 1 == loanBracket.MaximumAmount) { //Start recalculating the max and min amounts. for (int j = i; j < orderedList.Count; j++) { decimal range = 0.0m; //If it is the first one. if (j == i) { range = orderedList[j].MaximumAmount - orderedList[j].MinimumAmount; orderedList[j].MinimumAmount = loanBracket.MaximumAmount + 1; orderedList[j].MaximumAmount = orderedList[j].MinimumAmount + range; } else { range = orderedList[j].MaximumAmount - orderedList[j].MinimumAmount; orderedList[j].MinimumAmount = orderedList[j - 1].MaximumAmount + 1; orderedList[j].MaximumAmount = orderedList[j].MinimumAmount + range; } } //We found the spot, and we have recalculated the amounts, //thus break from the loop. //Indicate we successfully added reArranged = true; break; } } //If we resorted everything, then add the new loan //bracket if (!reArranged) { throw new ZiblerBusinessComponentsException ( Resources.SystemParametersOperationMsgLoanBracketAmountNotContinuos); } else financialInstitution.AddLoanBracket (loanBracket); } } /* If the exception was thrown here, just pass it up */ catch (ZiblerBusinessComponentsException ex) { throw; } /* Catch any Data Layer or other exception and throw an unkown exception */ catch (Exception ex) { ZiblerBusinessComponentsUnknownException exc = new ZiblerBusinessComponentsUnknownException (ex); /* Throw the new exception */ throw exc; } }
/// <summary> /// Updates a loan bracket in the system /// </summary> /// <param name="loanBracketToUpdate">Loan bracket to update</param> public void UpdateLoanBracket(LoanBracket loanBracketToUpdate) { try { IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO (); //Get all existing Loan Brackets FinancialInstitution financialInstitution = financialInstitutionDAO.GetFinancialInstitutionByName ( loanBracketToUpdate.FinancialInstitution.Name); //Make sure the name is not repeated. foreach (LoanBracket existingBracket in financialInstitution.LoanBrackets) { if (existingBracket.Name == loanBracketToUpdate.Name && existingBracket.Id != loanBracketToUpdate.Id) { throw new ZiblerBusinessComponentsException ( Resources.SystemParametersOperationMsgLoanBracketExists); } } } /* If the exception was thrown here, just pass it up */ catch (ZiblerBusinessComponentsException ex) { throw; } /* Catch any Data Layer or other exception and throw an unkown exception */ catch (Exception ex) { ZiblerBusinessComponentsUnknownException exc = new ZiblerBusinessComponentsUnknownException (ex); /* Throw the new exception */ throw exc; } }
/// <summary> /// Removes the list of Loan Parameters from the Loan Bracket /// </summary> /// <param name="loanBracketToUpdate">loanBracketToUpdate</param> /// <param name="selectedLoanParameterIds">selectedIds</param> public void RemoveParametersFromLoanBracket(LoanBracket loanBracketToUpdate, IList<int> selectedLoanParameterIds) { try { ILoanParameterDAO loanParameterDAO = _daoFactory.GetLoanParameterDAO (); foreach (int selectedId in selectedLoanParameterIds) { LoanParameter loanParameter = loanParameterDAO.FindById (selectedId); if (loanParameter != null) { loanBracketToUpdate.RemoveLoanParameter (loanParameter); } else { throw new ZiblerBusinessComponentsException ( Resources.SystemParametersOperationsMsgLoanParameterNotExists); } } } /* If the exception was thrown here, just pass it up */ catch (ZiblerBusinessComponentsException ex) { throw; } /* Catch any Data Layer or other exception and throw an unkown exception */ catch (Exception ex) { ZiblerBusinessComponentsUnknownException exc = new ZiblerBusinessComponentsUnknownException (ex); /* Throw the new exception */ throw exc; } }