/// <summary>
        /// This method delete a transaction
        /// </summary>
        /// <param name="transactionID">transactionID</param>
        /// <returns></returns>
        public bool DeleteTransaction(int transactionID)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var adminTransactionRepo =
                        new AdminTransactionRepository(new EFRepository <AdminTransaction>(), unitOfWork);

                    ObjectSet <AdminTransaction> transactionObjSet =
                        ((CurrentDeskClientsEntities)adminTransactionRepo.Repository.UnitOfWork.Context).AdminTransactions;

                    //Get particular transaction
                    var transaction = transactionObjSet.Where(tran => tran.PK_TransactionID == transactionID).FirstOrDefault();

                    //Set IsDeleted true and save
                    if (transaction != null)
                    {
                        transaction.IsDeleted = true;
                        adminTransactionRepo.Save();
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw;
            }
        }
        /// <summary>
        /// This method returns list of clients transactions of particular type
        /// </summary>
        /// <param name="clientIds">clientIds</param>
        /// <param name="transactionType">transactionType</param>
        /// <param name="organizationID">organizationID</param>
        /// <returns></returns>
        public List <AdminTransaction> GetAllClientsTransactionOfParticulaType(string clientIds, int transactionType, int organizationID)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var adminTransactionRepo =
                        new AdminTransactionRepository(new EFRepository <AdminTransaction>(), unitOfWork);

                    ObjectSet <AdminTransaction> transactionObjSet =
                        ((CurrentDeskClientsEntities)adminTransactionRepo.Repository.UnitOfWork.Context)
                        .AdminTransactions;

                    var allTransactions = transactionObjSet.Where(tran => tran.IsDeleted == false && tran.FK_OrganizationID == organizationID).ToList();

                    //All pending transactions
                    var allPendingTransactions =
                        allTransactions.Where(
                            transaction => clientIds.Contains(transaction.FK_UserID.ToString()) &&
                            transaction.FK_AdminTransactionTypeID == transactionType &&
                            transaction.IsApproved == false)
                        .OrderByDescending(tran => tran.TransactionDate)
                        .ToList();

                    //Latest 5 approved transactions
                    var latestApprovedTransactions =
                        allTransactions.Where(
                            tran => clientIds.Contains(tran.FK_UserID.ToString()) &&
                            tran.FK_AdminTransactionTypeID == transactionType &&
                            tran.IsApproved == true).OrderByDescending(odr => odr.ApprovedDate).Take(5).ToList();

                    allPendingTransactions.AddRange(latestApprovedTransactions);

                    return(allPendingTransactions.OrderByDescending(odr => odr.TransactionDate).ToList());
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw;
            }
        }
        // Add your own data access methods here.  If you wish to
        // expose your public method to a WCF service, marked them with
        // the attribute [NCPublish], and another T4 template will generate your service contract

        /// <summary>
        /// This method adds new fund account request in AdminTransaction table
        /// </summary>
        /// <param name="newRequest">newRequest</param>
        /// <returns></returns>
        public bool AddNewAdminTransactionRequest(AdminTransaction newRequest)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var adminTransactionRepo =
                        new AdminTransactionRepository(new EFRepository <AdminTransaction>(), unitOfWork);

                    adminTransactionRepo.Add(newRequest);
                    adminTransactionRepo.Save();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                return(false);
            }
        }
        /// <summary>
        /// This method returns list of all incoming fund transfer request
        /// </summary>
        /// <returns></returns>
        public List <AdminTransaction> GetAllIncomingFundRequests(int organizationID)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var adminTransactionRepo =
                        new AdminTransactionRepository(new EFRepository <AdminTransaction>(), unitOfWork);

                    ObjectSet <AdminTransaction> transactionObjSet =
                        ((CurrentDeskClientsEntities)adminTransactionRepo.Repository.UnitOfWork.Context).AdminTransactions;

                    return(transactionObjSet.Include("FundingSource").Where(transaction => transaction.FK_AdminTransactionTypeID == (int)AdminTransactionType.IncomingFunds && transaction.FK_OrganizationID == organizationID && transaction.IsApproved == false && transaction.IsDeleted == false).ToList());
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw;
            }
        }
        /// <summary>
        /// This method returns sum of pending transfer request amount for an account
        /// </summary>
        /// <param name="accountNumber">accountNumber</param>
        /// <param name="organizationID">organizationID</param>
        /// <returns></returns>
        public decimal GetPendingTransferAmount(string accountNumber, int organizationID)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var adminTransactionRepo =
                        new AdminTransactionRepository(new EFRepository <AdminTransaction>(), unitOfWork);

                    ObjectSet <AdminTransaction> transactionObjSet =
                        ((CurrentDeskClientsEntities)adminTransactionRepo.Repository.UnitOfWork.Context).AdminTransactions;

                    return((decimal)transactionObjSet.Where(tran => tran.AccountNumber == accountNumber && tran.FK_OrganizationID == organizationID && (tran.FK_AdminTransactionTypeID == (int)AdminTransactionType.InternalTransfers || tran.FK_AdminTransactionTypeID == (int)AdminTransactionType.ConversionsRequests) && tran.IsApproved == false && tran.IsDeleted == false).ToList().Sum(tran => tran.TransactionAmount));
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw;
            }
        }
        /// <summary>
        /// Return details of a particular transaction
        /// </summary>
        /// <param name="pkTransactionID">pkTransactionID</param>
        /// <returns></returns>
        public AdminTransaction GetTransactionDetails(int pkTransactionID)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var adminTransactionRepo =
                        new AdminTransactionRepository(new EFRepository <AdminTransaction>(), unitOfWork);

                    ObjectSet <AdminTransaction> transactionObjSet =
                        ((CurrentDeskClientsEntities)adminTransactionRepo.Repository.UnitOfWork.Context).AdminTransactions;

                    //Return particular transaction
                    return(transactionObjSet.Include("FundingSource").Include("BankAccountInformation").Where(tran => tran.PK_TransactionID == pkTransactionID).FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw;
            }
        }
        /// <summary>
        /// This method approves a particular outgoing transaction
        /// </summary>
        /// <param name="approveTransaction">approveTransaction</param>
        /// <returns></returns>
        public bool ApproveOutgoingTransaction(AdminTransaction approveTransaction)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var adminTransactionRepo =
                        new AdminTransactionRepository(new EFRepository <AdminTransaction>(), unitOfWork);

                    ObjectSet <AdminTransaction> transactionObjSet =
                        ((CurrentDeskClientsEntities)adminTransactionRepo.Repository.UnitOfWork.Context).AdminTransactions;

                    //Get particular transaction
                    var transaction = transactionObjSet.Where(tran => tran.PK_TransactionID == approveTransaction.PK_TransactionID).FirstOrDefault();

                    //Update its fields
                    if (transaction != null)
                    {
                        transaction.TransactionAmount  = approveTransaction.TransactionAmount;
                        transaction.FeeAmount          = approveTransaction.FeeAmount;
                        transaction.ApprovedDate       = DateTime.UtcNow;
                        transaction.Notes              = approveTransaction.Notes;
                        transaction.FK_FundingSourceID = approveTransaction.FK_FundingSourceID;
                        transaction.IsApproved         = true;

                        adminTransactionRepo.Save();
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw;
            }
        }