private void updateCASA(DepositAccountOpeningObj entity, int customerId, string accountNumber)
        {
            decimal bal       = _dataContext.deposit_accountsetup.Where(x => x.DepositAccountId == entity.AccountTypeId).FirstOrDefault().InitialDeposit;
            decimal Ledgerbal = _dataContext.deposit_accountsetup.Where(x => x.DepositAccountId == entity.AccountTypeId).FirstOrDefault().InitialDeposit;
            decimal?irate     = _dataContext.deposit_accountsetup.Where(x => x.DepositAccountId == entity.AccountTypeId).FirstOrDefault().InterestRate;
            decimal lienBal   = _dataContext.deposit_accountsetup.Where(x => x.DepositAccountId == entity.AccountTypeId).FirstOrDefault().InitialDeposit;

            var         user        = _serverRequest.UserDataAsync().Result;
            credit_casa casaAccount = null;

            casaAccount = _dataContext.credit_casa.Where(x => x.CustomerId == customerId).FirstOrDefault();
            if (casaAccount == null)
            {
                var customerAccount = new credit_casa
                {
                    AccountName     = $"{entity.Firstname}{entity.Surname}",//entity.Firstname + " " + entity.Surname,
                    AccountNumber   = accountNumber,
                    AccountStatusId = (int)CASAAccountStatusEnum.Inactive,
                    //ActionBy = entity.actionBy,
                    ActionDate       = DateTime.Now,
                    AprovalStatusId  = (int)ApprovalStatus.Pending,
                    AvailableBalance = bal,
                    BranchId         = 1,
                    CompanyId        = 7,
                    CustomerId       = customerId,
                    //CustomerSensitivityLevelId = entity.customerSensitivityLevelId,
                    EffectiveDate    = DateTime.Now,
                    HasLien          = true,
                    HasOverdraft     = true,
                    InterestRate     = irate,
                    IsCurrentAccount = false,
                    LedgerBalance    = Ledgerbal,
                    LienAmount       = lienBal,
                    //MISCode = "",
                    OperationId = (int)OperationsEnum.CasaAccountApproval,
                    //OverdraftAmount = 0,
                    //OverdraftExpiryDate = entity.overdraftExpiryDate,
                    //OverdraftInterestRate = 0,
                    //PostNoStatusId = entity.postNoStatusId,
                    ProductId             = entity.AccountTypeId,
                    RelationshipManagerId = 0,
                    RelationshipOfficerId = 0,
                    //TEAMMISCode = "",
                    FromDeposit = true,
                    //Tenor = entity.tenor,
                    //TerminalDate = entity.terminalDate,
                    Active    = true,
                    Deleted   = false,
                    CreatedBy = user.UserName,
                    CreatedOn = DateTime.Now,
                    UpdatedBy = user.UserName,
                    UpdatedOn = DateTime.Now,
                };
                _dataContext.credit_casa.Add(customerAccount);
                _dataContext.SaveChanges();
            }
        }
        public async Task <int> AddUpdateCustomerAsync(DepositAccountOpeningObj entity)
        {
            try
            {
                if (entity == null)
                {
                    return(0);
                }
                int inserted_id = 0;
                deposit_accountopening CustomerExist = null;
                var accountNumber = GeneralHelpers.GenerateRandomDigitCode(10);

                if (entity.CustomerId > 0)
                {
                    CustomerExist = _dataContext.deposit_accountopening.Find(entity.CustomerId);
                    if (CustomerExist != null)
                    {
                        CustomerExist.AccountCategoryId     = entity.AccountCategoryId;
                        CustomerExist.AccountTypeId         = entity.AccountTypeId;
                        CustomerExist.CustomerTypeId        = entity.CustomerTypeId;
                        CustomerExist.AccountNumber         = entity.AccountNumber;
                        CustomerExist.Title                 = entity.Title;
                        CustomerExist.Surname               = entity.Surname;
                        CustomerExist.Firstname             = entity.Firstname;
                        CustomerExist.Othername             = entity.Othername;
                        CustomerExist.MaritalStatusId       = entity.MaritalStatusId;
                        CustomerExist.RelationshipOfficerId = entity.RelationshipOfficerId;
                        CustomerExist.GenderId              = entity.GenderId;
                        CustomerExist.BirthCountryId        = entity.BirthCountryId;
                        CustomerExist.DOB = entity.DOB;
                        CustomerExist.MotherMaidenName = entity.MotherMaidenName;
                        CustomerExist.TaxIDNumber      = entity.TaxIDNumber;
                        CustomerExist.BVN                  = entity.BVN;
                        CustomerExist.Nationality          = entity.Nationality;
                        CustomerExist.ResidentPermitNumber = entity.ResidentPermitNumber;
                        CustomerExist.PermitIssueDate      = entity.PermitIssueDate;
                        CustomerExist.PermitExpiryDate     = entity.PermitExpiryDate;
                        CustomerExist.SocialSecurityNumber = entity.SocialSecurityNumber;
                        CustomerExist.StateOfOrigin        = entity.StateOfOrigin;
                        CustomerExist.LocalGovernment      = entity.LocalGovernment;
                        CustomerExist.ResidentOfCountry    = entity.ResidentOfCountry;
                        CustomerExist.Address1             = entity.Address1;
                        CustomerExist.Address2             = entity.Address2;
                        CustomerExist.City                 = entity.City;
                        CustomerExist.StateId              = entity.StateId;
                        CustomerExist.CountryId            = entity.CountryId;
                        CustomerExist.Email                = entity.Email;
                        CustomerExist.MailingAddress       = entity.MailingAddress;
                        CustomerExist.MobileNumber         = entity.MobileNumber;
                        CustomerExist.InternetBanking      = entity.InternetBanking;
                        CustomerExist.EmailStatement       = entity.EmailStatement;
                        CustomerExist.Card                 = entity.Card;
                        CustomerExist.SmsAlert             = entity.SmsAlert;
                        CustomerExist.EmailAlert           = entity.EmailAlert;
                        CustomerExist.Token                = entity.Token;
                        CustomerExist.EmploymentType       = entity.EmploymentType;
                        CustomerExist.EmployerName         = entity.EmployerName;
                        CustomerExist.EmployerAddress      = entity.EmployerAddress;
                        CustomerExist.EmployerState        = entity.EmployerState;
                        CustomerExist.Occupation           = entity.Occupation;
                        CustomerExist.BusinessName         = entity.BusinessName;
                        CustomerExist.BusinessAddress      = entity.BusinessAddress;
                        CustomerExist.BusinessState        = entity.BusinessState;
                        CustomerExist.JobTitle             = entity.JobTitle;
                        CustomerExist.Other                = entity.Other;
                        CustomerExist.DeclarationDate      = entity.DeclarationDate;
                        CustomerExist.DeclarationCompleted = entity.DeclarationCompleted;
                        CustomerExist.SoleSignatory        = entity.SoleSignatory;
                        CustomerExist.MaxNoOfSignatory     = entity.MaxNoOfSignatory;
                        CustomerExist.RegistrationNumber   = entity.RegistrationNumber;
                        CustomerExist.Industry             = entity.Industry;
                        CustomerExist.Jurisdiction         = entity.Jurisdiction;
                        CustomerExist.Website              = entity.Website;
                        CustomerExist.NatureOfBusiness     = entity.NatureOfBusiness;
                        CustomerExist.AnnualRevenue        = entity.AnnualRevenue;
                        CustomerExist.IsStockExchange      = entity.IsStockExchange;
                        CustomerExist.Stock                = entity.Stock;
                        CustomerExist.RegisteredAddress    = entity.RegisteredAddress;
                        CustomerExist.ScumlNumber          = entity.ScumlNumber;
                        CustomerExist.UpdatedBy            = entity.CreatedBy;
                        CustomerExist.UpdatedOn            = DateTime.Now;
                    }
                }
                else
                {
                    CustomerExist = new deposit_accountopening
                    {
                        CustomerId            = entity.CustomerId,
                        AccountCategoryId     = entity.AccountCategoryId,
                        AccountTypeId         = entity.AccountTypeId,
                        CustomerTypeId        = entity.CustomerTypeId,
                        AccountNumber         = accountNumber,
                        Title                 = entity.Title,
                        Surname               = entity.Surname,
                        Firstname             = entity.Firstname,
                        Othername             = entity.Othername,
                        MaritalStatusId       = entity.MaritalStatusId,
                        RelationshipOfficerId = entity.RelationshipOfficerId,
                        GenderId              = entity.GenderId,
                        BirthCountryId        = entity.BirthCountryId,
                        DOB = entity.DOB,
                        MotherMaidenName = entity.MotherMaidenName,
                        TaxIDNumber      = entity.TaxIDNumber,
                        BVN                  = entity.BVN,
                        Nationality          = entity.Nationality,
                        ResidentPermitNumber = entity.ResidentPermitNumber,
                        PermitIssueDate      = entity.PermitIssueDate,
                        PermitExpiryDate     = entity.PermitExpiryDate,
                        SocialSecurityNumber = entity.SocialSecurityNumber,
                        StateOfOrigin        = entity.StateOfOrigin,
                        LocalGovernment      = entity.LocalGovernment,
                        ResidentOfCountry    = entity.ResidentOfCountry,
                        Address1             = entity.Address1,
                        Address2             = entity.Address2,
                        City                 = entity.City,
                        StateId              = entity.StateId,
                        CountryId            = entity.CountryId,
                        Email                = entity.Email,
                        MailingAddress       = entity.MailingAddress,
                        MobileNumber         = entity.MobileNumber,
                        InternetBanking      = entity.InternetBanking,
                        EmailStatement       = entity.EmailStatement,
                        Card                 = entity.Card,
                        SmsAlert             = entity.SmsAlert,
                        EmailAlert           = entity.EmailAlert,
                        Token                = entity.Token,
                        EmploymentType       = entity.EmploymentType,
                        EmployerName         = entity.EmployerName,
                        EmployerAddress      = entity.EmployerAddress,
                        EmployerState        = entity.EmployerState,
                        Occupation           = entity.Occupation,
                        BusinessName         = entity.BusinessName,
                        BusinessAddress      = entity.BusinessAddress,
                        BusinessState        = entity.BusinessState,
                        JobTitle             = entity.JobTitle,
                        Other                = entity.Other,
                        DeclarationDate      = entity.DeclarationDate,
                        DeclarationCompleted = entity.DeclarationCompleted,
                        SoleSignatory        = entity.SoleSignatory,
                        MaxNoOfSignatory     = entity.MaxNoOfSignatory,
                        RegistrationNumber   = entity.RegistrationNumber,
                        Industry             = entity.Industry,
                        Jurisdiction         = entity.Jurisdiction,
                        Website              = entity.Website,
                        NatureOfBusiness     = entity.NatureOfBusiness,
                        AnnualRevenue        = entity.AnnualRevenue,
                        IsStockExchange      = entity.IsStockExchange,
                        Stock                = entity.Stock,
                        RegisteredAddress    = entity.RegisteredAddress,
                        ScumlNumber          = entity.ScumlNumber,
                        Active               = true,
                        Deleted              = false,
                        CreatedBy            = entity.CreatedBy,
                        CreatedOn            = DateTime.Now,
                    };
                    _dataContext.deposit_accountopening.Add(CustomerExist);
                }
                using (var trans = _dataContext.Database.BeginTransaction())
                {
                    try
                    {
                        _dataContext.SaveChanges();
                        inserted_id = CustomerExist.CustomerId;
                        updateCASA(entity, inserted_id, accountNumber);
                        trans.Commit();
                        return(inserted_id);
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }