/// <summary>
        /// Creates a new LoanParameter and adds it to the system
        /// </summary>
        /// <param name="financialInstitutionName">Financial Institution name</param>
        /// <param name="userName">User name</param>
        /// <param name="loanParameter">New LoanParameter</param>
        /// <param name="loanCommissionIds">List of loan commissions to be associated to this new loan parameter</param>
        /// <param name="interestRateId">Interest Rate Id</param>
        /// <exception cref="ZiblerBusinessComponentsException" />
        public void CreateNewLoanParameter(string financialInstitutionName,
            string userName,
            LoanParameter loanParameter,
            IList<int> loanCommissionIds,
            int interestRateId)
        {
            try
            {
                IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO ();
                ILoanCommissionDAO loanCommissionDAO = _daoFactory.GetLoanCommissionDAO ();
                IInterestRateDAO interestRateDAO = _daoFactory.GetInterestRateDAO ();

                //Verify the user does not exist in the system first.
                if (financialInstitutionDAO.LoanParameterExists (financialInstitutionName,
                                                                 loanParameter.Name))
                {
                    throw new ZiblerBusinessComponentsException (
                        Resources.SystemParametersOperationMsgLoanParameterExists);
                }
                else
                {
                    bool defaultLoanParameterExists = financialInstitutionDAO.DefaultLoanParameterExists (
                        financialInstitutionName,
                        loanParameter.LoanType);

                    //See if the parameter was marked as default.
                    //if so, then we need to verify there is no other
                    //parameter marked as such.
                    if (loanParameter.IsDefault)
                    {
                        if (defaultLoanParameterExists)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.SystemParametersOperationsMsgDefaultLoanParameterExists);
                        }
                    }
                    else
                    {
                        //If this loan parameter is not marked by defualt,
                        //and there is no default parameter in the system,
                        //we raise an exception indicating that they should
                        //select one parameter by default.
                        if (defaultLoanParameterExists == false)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.SystemParametersOperationsMsgAtLeastOneDefaultLoanParameter);
                        }
                    }

                    //TODO: Verify if it is better to get all commissions or to get only the ones with the given Ids.
                    //		I am loading all the loan commissions at the same time and this could cause some overload
                    //		in the system
                    IList<LoanCommission> loanCommissions = loanCommissionDAO.GetAllLoanCommissions (
                        financialInstitutionName);

                    foreach (LoanCommission loanCommission in loanCommissions)
                    {
                        if (loanCommissionIds.Contains (loanCommission.Id))
                            loanParameter.AddLoanCommission (loanCommission);
                    }

                    //TODO: Verify the Interest Rate has not been deleted
                    //		verify interestRate != nll

                    //Get Interest Rate
                    InterestRate interestRate = interestRateDAO.FindById (interestRateId);
                    if (interestRate != null)
                    {
                        loanParameter.InterestRate = interestRate;
                    }
                    else
                    {
                        throw new ZiblerBusinessComponentsException (Resources.RecordNotFound);
                    }

                    //Get the financial institution, and add the new interest to it.
                    FinancialInstitution financialInstitution = financialInstitutionDAO.GetFinancialInstitutionByName (
                        financialInstitutionName);
                    financialInstitution.AddLoanParameter (loanParameter);
                }
            }
            /* 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>
        /// Update the LoanParameter and save it to the system
        /// </summary>
        /// <param name="loanParameterToUpdate">LoanParameter to be updated</param>
        /// <param name="loanCommissionIds">List of loan commissions to be associated to this loan parameter</param>
        /// <param name="interestRateId">Interest Rate Id</param>
        /// <exception cref="ZiblerBusinessComponentsException" />
        public void UpdateLoanParameter(LoanParameter loanParameterToUpdate,
            IList<int> loanCommissionIds,
            int interestRateId)
        {
            try
            {
                IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO ();
                ILoanCommissionDAO loanCommissionDAO = _daoFactory.GetLoanCommissionDAO ();
                IInterestRateDAO interestRateDAO = _daoFactory.GetInterestRateDAO ();
                ILoanParameterDAO loanParameterDAO = _daoFactory.GetLoanParameterDAO ();

                string oldName = loanParameterDAO.GetLoanParameterName (loanParameterToUpdate.Id);

                if (oldName == "")
                    throw new ZiblerBusinessComponentsException (Resources.RecordNotFound);
                else
                {
                    //Before we go into updating or not (based on the name) we verify the Default
                    //status.
                    //If we have marked it as default
                    if (loanParameterToUpdate.IsDefault)
                    {
                        //Default parameter exists for the type and it is not the one with the Id
                        bool defaultExists = financialInstitutionDAO.DefaultLoanParameterExists (
                            loanParameterToUpdate.FinancialInstitution.Name,
                            loanParameterToUpdate.Id,
                            loanParameterToUpdate.LoanType);

                        if (defaultExists)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.SystemParametersOperationsMsgDefaultLoanParameterExists);
                        }
                    }
                    else
                    {
                        //Make sure the sistem still has a default loan parameter for both types of loans and that it is not
                        //the one we are changing
                        //Default parameter exists for the type and it is not the one with the Id
                        bool defaultWorkingCapital = financialInstitutionDAO.DefaultLoanParameterExists (
                            loanParameterToUpdate.FinancialInstitution.Name,
                            loanParameterToUpdate.Id,
                            LoanType.CapitalDeTrabajo);
                        bool defaultFixedAsset = financialInstitutionDAO.DefaultLoanParameterExists (
                            loanParameterToUpdate.FinancialInstitution.Name,
                            loanParameterToUpdate.Id,
                            LoanType.Refaccionario);

                        if (!defaultWorkingCapital)
                            throw new ZiblerBusinessComponentsException (
                                Resources.SystemParametersOperationsMsgAtLeastOneDefaultLoanParameter);

                        if (!defaultFixedAsset)
                            throw new ZiblerBusinessComponentsException (
                                Resources.SystemParametersOperationsMsgAtLeastOneDefaultLoanParameter);
                    }

                    if (oldName == loanParameterToUpdate.Name)
                    {
                        //Remove all and just readd the ones that should be associated.
                        loanParameterToUpdate.LoanCommissions.Clear ();

                        //TODO: Verify if it is better to get all commissions or to get only the ones with the given Ids.
                        //		I am loading all the loan commissions at the same time and this could cause some overload
                        //		in the system
                        IList<LoanCommission> loanCommissions = loanCommissionDAO.GetAllLoanCommissions (
                            loanParameterToUpdate.FinancialInstitution.Name);

                        foreach (LoanCommission loanCommission in loanCommissions)
                        {
                            //If we are to add this loan commission. Note that the Commission
                            //won't be added twice due to the nature of the collection.
                            if (loanCommissionIds.Contains (loanCommission.Id))
                                loanParameterToUpdate.AddLoanCommission (loanCommission);
                        }

                        //Only update if hte interest rate has changed.
                        if (loanParameterToUpdate.InterestRate.Id != interestRateId)
                        {
                            InterestRate interestRate = interestRateDAO.FindById (interestRateId);
                            loanParameterToUpdate.InterestRate = interestRate;
                        }

                        loanParameterDAO.MakePersistent (loanParameterToUpdate);
                    }
                    else
                    {
                        if (financialInstitutionDAO.LoanParameterExists (
                            loanParameterToUpdate.FinancialInstitution.Name,
                            loanParameterToUpdate.Name))
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.SystemParametersOperationMsgLoanParameterExists);
                        }
                        else
                        {
                            //Remove all and just readd the ones that should be associated.
                            loanParameterToUpdate.LoanCommissions.Clear ();

                            //TODO: Verify if it is better to get all commissions or to get only the ones with the given Ids.
                            //		I am loading all the loan commissions at the same time and this could cause some overload
                            //		in the system
                            IList<LoanCommission> loanCommissions = loanCommissionDAO.GetAllLoanCommissions (
                                loanParameterToUpdate.FinancialInstitution.Name);

                            foreach (LoanCommission loanCommission in loanCommissions)
                            {
                                //If we are to add this loan commission. Note that the Commission
                                //won't be added twice due to the nature of the collection.
                                if (loanCommissionIds.Contains (loanCommission.Id))
                                    loanParameterToUpdate.AddLoanCommission (loanCommission);
                            }

                            //Only update if hte interest rate has changed.
                            if (loanParameterToUpdate.InterestRate.Id != interestRateId)
                            {
                                InterestRate interestRate = interestRateDAO.FindById (interestRateId);
                                loanParameterToUpdate.InterestRate = interestRate;
                            }

                            loanParameterDAO.MakePersistent (loanParameterToUpdate);
                        }
                    }
                }
            }
            /* 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;
            }
        }