public bool ValidateProduct(ISavingProduct savingsProduct, int clientTypeCounter)
        {
            if (string.IsNullOrEmpty(savingsProduct.Name))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.NameIsEmpty);
            }

            if (string.IsNullOrEmpty(savingsProduct.Code))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CodeIsEmpty);
            }

            if (savingsProduct.Id == 0 && _savingProductManager.IsThisProductNameAlreadyExist(savingsProduct.Name))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.DuplicateProductName);
            }

            if (savingsProduct.Id == 0 && _savingProductManager.IsThisProductCodeAlreadyExist(savingsProduct.Code))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.DuplicateProductCode);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.InitialAmountMin, savingsProduct.InitialAmountMax, null))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InitialAmountIsInvalid);
            }

            if (savingsProduct.InitialAmountMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InitialAmountMinIsInvalid);
            }

            if (!ServicesHelper.CheckIfValueBetweenMinAndMax(savingsProduct.BalanceMin, savingsProduct.BalanceMax, savingsProduct.InitialAmountMin))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InitialAmountMinNotInBalance);
            }

            if (!ServicesHelper.CheckIfValueBetweenMinAndMax(savingsProduct.BalanceMin, savingsProduct.BalanceMax, savingsProduct.InitialAmountMax))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InitialAmountMaxNotInBalance);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.BalanceMin, savingsProduct.BalanceMax, null))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.BalanceIsInvalid);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.InterestRateMin, savingsProduct.InterestRateMax, savingsProduct.InterestRate))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestRateMinMaxIsInvalid);
            }

            if (savingsProduct.InterestRate.HasValue && savingsProduct.InterestRate < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestRateIsInvalid);
            }

            if (!savingsProduct.InterestRate.HasValue && savingsProduct.InterestRateMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestRateMinIsInvalid);
            }

            if (savingsProduct.Currency == null)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CurrencyIsEmpty);
            }

            if (savingsProduct.Currency.Id == 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CurrencyIsEmpty);
            }

            if (clientTypeCounter < 1)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ClientTypeIsInvalid);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.EntryFeesMin, savingsProduct.EntryFeesMax, savingsProduct.EntryFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.EntryFeesMinMaxIsInvalid);
            }

            if (savingsProduct.EntryFees.HasValue && savingsProduct.EntryFees.Value < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.EntryFeesIsInvalid);
            }

            if (savingsProduct is SavingsBookProduct)
            {
                ValidateSavingBookProduct((SavingsBookProduct)savingsProduct);
            }
            return(true);
        }
        private static void ValidateSavingBookProduct(SavingsBookProduct savingsProduct)
        {
            if (!Enum.IsDefined(typeof(OSavingInterestFrequency), savingsProduct.InterestFrequency.ToString()))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestsFrequencyIsInvalid);
            }

            if (!Enum.IsDefined(typeof(OSavingInterestBase), savingsProduct.InterestBase.ToString()))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestsBaseIsInvalid);
            }

            if (savingsProduct.InterestBase == OSavingInterestBase.Monthly &&
                (savingsProduct.InterestFrequency != OSavingInterestFrequency.EndOfYear &&
                 savingsProduct.InterestFrequency != OSavingInterestFrequency.EndOfMonth))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestBaseIncompatibleFrequency);
            }

            if (savingsProduct.InterestBase == OSavingInterestBase.Weekly &&
                (savingsProduct.InterestFrequency == OSavingInterestFrequency.EndOfDay))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestBaseIncompatibleFrequency);
            }

            if (savingsProduct.InterestBase != OSavingInterestBase.Daily &&
                (!savingsProduct.CalculAmountBase.HasValue))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CalculAmountBaseIsNull);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.WithdrawingMin, savingsProduct.WithdrawingMax, null))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.WithdrawAmountIsInvalid);
            }

            //if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.AMMin, savingsProduct.AMMax, null))
            //    throw new OpenCbsSavingProductException("Account maintenance fee is invalid");


            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.DepositMin, savingsProduct.DepositMax, null))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.DepositAmountIsInvalid);
            }

            if (savingsProduct.DepositMin <= 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.DepositMinAmountIsInvalid);
            }
            if (savingsProduct.ChequeDepositMin <= 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ChequeDepositIsInvalid);
            }
            if (savingsProduct.ChequeDepositMin > savingsProduct.ChequeDepositMax)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ChequeDepositIsInvalid);
            }

            if (savingsProduct.WithdrawingMin <= 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.WithdrawMinAmountIsInvalid);
            }

            //if (savingsProduct.AMMin <= 0)
            //    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.WithdrawMinAmountIsInvalid);

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.TransferMin, savingsProduct.TransferMax, null))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.TransferAmountIsInvalid);
            }

            if (savingsProduct.DepositFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.DepositFeesMinIsInvalid);
            }
            if (savingsProduct.ChequeDepositFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ChequeDepositFeesIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.DepositFeesMin, savingsProduct.DepositFeesMax, savingsProduct.DepositFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.DepositFeesIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.ChequeDepositFeesMin, savingsProduct.ChequeDepositFeesMax, savingsProduct.ChequeDepositFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ChequeDepositFeesIsInvalid);
            }

            if (savingsProduct.ReopenFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ReopenFeesMinIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.ReopenFeesMin, savingsProduct.ReopenFeesMax, savingsProduct.ReopenFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ReopenFeesIsInvalid);
            }

            if (savingsProduct.OverdraftFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.OverdraftFeesMinIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.OverdraftFeesMin, savingsProduct.OverdraftFeesMax, savingsProduct.OverdraftFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.OverdraftFeesIsInvalid);
            }

            if (savingsProduct.AgioFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.AgioFeesMinIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.AgioFeesMin, savingsProduct.AgioFeesMax, savingsProduct.AgioFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.AgioFeesIsInvalid);
            }

            if (savingsProduct.CloseFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CloseFeesMinIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.CloseFeesMin, savingsProduct.CloseFeesMax, savingsProduct.CloseFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CloseFeesIsInvalid);
            }



            if (savingsProduct.InstrumentFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InstrumentFeesMinIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.InstrumentFeesMin, savingsProduct.InstrumentFeesMax, savingsProduct.InstrumentFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InstrumentFeesIsInvalid);
            }

            if (savingsProduct.SearchFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.SearchFeesMinIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.SearchFeesMin, savingsProduct.SearchFeesMax, savingsProduct.SearchFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.SearchFeesIsInvalid);
            }


            if (savingsProduct.DutyStampFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.OtherFeesMinIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.DutyStampFeesMin, savingsProduct.DutyStampFeesMax, savingsProduct.DutyStampFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.OtherFeesIsInvalid);
            }



            if (savingsProduct.ManagementFeesMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ManagementFeesMinIsInvalid);
            }
            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.ManagementFeesMin, savingsProduct.ManagementFeesMax, savingsProduct.ManagementFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ManagementFeesIsInvalid);
            }

            if (savingsProduct.TransferMin <= 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.TransferAmountMinIsInvalid);
            }

            if (!Enum.IsDefined(typeof(OSavingsFeesType), savingsProduct.WithdrawFeesType.ToString()))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.WithdrawFeesTypeEmpty);
            }

            if (savingsProduct.WithdrawFeesType == OSavingsFeesType.Flat)
            {
                if (savingsProduct.FlatWithdrawFees.HasValue && savingsProduct.FlatWithdrawFees.Value < 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.FlatWithdrawFeesIsInvalid);
                }

                if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.FlatWithdrawFeesMin, savingsProduct.FlatWithdrawFeesMax, savingsProduct.FlatWithdrawFees))
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.FlatWithdrawFeesMinMaxIsInvalid);
                }

                if (!savingsProduct.FlatWithdrawFees.HasValue && savingsProduct.FlatWithdrawFeesMin.Value < 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.FlatWithdrawFeesMinIsInvalid);
                }
            }
            else
            {
                if (savingsProduct.RateWithdrawFees.HasValue && savingsProduct.RateWithdrawFees.Value < 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.RateWithdrawFeesIsInvalid);
                }

                if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.RateWithdrawFeesMin, savingsProduct.RateWithdrawFeesMax, savingsProduct.RateWithdrawFees))
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.RateWithdrawFeesMinMaxIsInvalid);
                }

                if (!savingsProduct.RateWithdrawFees.HasValue && savingsProduct.RateWithdrawFeesMin.Value < 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.RateWithdrawFeesMinIsInvalid);
                }
            }

            if (!Enum.IsDefined(typeof(OSavingsFeesType), savingsProduct.TransferFeesType.ToString()))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.TransferFeesTypeEmpty);
            }

            if (savingsProduct.TransferFeesType == OSavingsFeesType.Flat)
            {
                if (savingsProduct.FlatTransferFees.HasValue && savingsProduct.FlatTransferFees.Value < 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.FlatTransferFeesIsInvalid);
                }

                if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.FlatTransferFeesMin, savingsProduct.FlatTransferFeesMax, savingsProduct.FlatTransferFees))
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.FlatTransferFeesMinMaxIsInvalid);
                }

                if (!savingsProduct.FlatTransferFees.HasValue && savingsProduct.FlatTransferFeesMin.Value < 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.FlatTransferFeesMinIsInvalid);
                }
            }
            else
            {
                if (savingsProduct.RateTransferFees.HasValue && savingsProduct.RateTransferFees.Value < 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.RateTransferFeesIsInvalid);
                }

                if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.RateTransferFeesMin, savingsProduct.RateTransferFeesMax, savingsProduct.RateTransferFees))
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.RateTransferFeesMinMaxIsInvalid);
                }

                if (!savingsProduct.RateTransferFees.HasValue && savingsProduct.RateTransferFeesMin.Value < 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.RateTransferFeesMinIsInvalid);
                }
            }

            ValidateInterBranchTransferFees(savingsProduct);

            if (!savingsProduct.OverdraftFees.HasValue && !(savingsProduct.OverdraftFeesMin.HasValue && savingsProduct.OverdraftFeesMax.HasValue))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.OverdraftFeesIsInvalid);
            }
            if (!savingsProduct.AgioFees.HasValue && !(savingsProduct.AgioFeesMin.HasValue && savingsProduct.AgioFeesMax.HasValue))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.AgioFeesIsInvalid);
            }
            if (savingsProduct.UseTermDeposit)
            {
                if (savingsProduct.TermDepositPeriodMin > savingsProduct.TermDepositPeriodMax)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.PostingFrequencyIsInvalid);
                }
                if (savingsProduct.TermDepositPeriodMax <= 0 || savingsProduct.TermDepositPeriodMin <= 0)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.PostingFrequencyIsInvalid);
                }
                if (savingsProduct.TermDepositPeriodMin == null || savingsProduct.TermDepositPeriodMax == null)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.PostingFrequencyIsInvalid);
                }
                if (savingsProduct.Periodicity == null)
                {
                    throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.PeriodicityIsNotSet);
                }
            }

            return;
        }