public void AddUnPaidPurchaseScaleExpenses(int scaleId)
        {
            // Search for all expenses that matches scaleId.
            ExpensesRequestLibrary lib             = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            string refTableName                    = new Model.Scale().GetType().Name;
            IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(scaleId, refTableName, new[] { "Payment", "Paid_Party_To" });
            ScaleLibrary scaleLib                  = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());

            foreach (var item in expenses)
            {
                // If scale expense already exists.
                if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null)
                {
                    // Get scale entity
                    Scale scale = scaleLib.GetByID(item.Reference_ID.ToString(), new string[] { "Dispatch_Request_No" });
                    if (item.Paid_Party_To == null)
                    {
                        item.Paid_Party_To = new Party();
                    }
                    // Add eexpense to TempList.
                    TempEntityList.Add(item);
                    // Add dispatcher expense.
                    if (scale.Dispatch_Request_No != null && scale.Dispatch_Request_No.ID > 0)
                    {
                        AddUnPaidPurchaseDispatcherExpenses(scale.Dispatch_Request_No.ID);
                    }
                }
            }
        }
        private void AddNonInvoiceSellingDispatcherExpenses(int bookingId, string containerNo)
        {
            // Search for expenses that matches dispatcher id.
            DispatcherRequestLibrary        dispathcerRequestLib = new DispatcherRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            IEnumerable <DispatcherRequest> dispatcherReqs       = dispathcerRequestLib.GetDispatcherByBookingAndContainerNo(bookingId, containerNo, new string[] { "Booking_Ref_No", "Container" });

            foreach (DispatcherRequest dispatcherReq in dispatcherReqs)
            {
                ExpensesRequestLibrary lib             = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                string refTableName                    = new Model.DispatcherRequest().GetType().Name;
                IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(dispatcherReq.ID, refTableName, new[] { "Payment", "Paid_Party_To", "Invoice" });
                foreach (var item in expenses)
                {
                    // If expense already exists.
                    if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null)
                    {
                        // If party is null.
                        if (item.Paid_Party_To == null)
                        {
                            item.Paid_Party_To = new Party();
                        }

                        // Add to TempList.
                        TempEntityList.Add(item);
                    }
                }
            }
        }
        private void AddUnPaidPurchaseDispatcherExpenses(int dispathcerId)
        {
            // Search for expenses that matches dispatcher id.
            ExpensesRequestLibrary lib             = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            string refTableName                    = new Model.DispatcherRequest().GetType().Name;
            IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(dispathcerId, refTableName, new[] { "Payment", "Paid_Party_To" });

            foreach (var item in expenses)
            {
                // If expense already exists.
                if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null)
                {
                    // If party is null.
                    if (item.Paid_Party_To == null)
                    {
                        item.Paid_Party_To = new Party();
                    }

                    // Add to TempList.
                    TempEntityList.Add(item);
                }
            }
        }