/// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        /// <returns></returns>
        public bool DeleteDirect(int assetId, int companyId)
        {
            // Verify in use
            if (!InUse(assetId, companyId))
            {
                // Delete laterals
                // ... Define initial models
                LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);

                // ... Load laterals
                AssetSewerLateralGateway assetSewerLateralGateway = new AssetSewerLateralGateway();
                assetSewerLateralGateway.LoadBySectionId(assetId, companyId);

                // ... Delete laterals
                foreach (AssetsTDS.AM_ASSET_SEWER_LATERALRow rowLateral in (AssetsTDS.AM_ASSET_SEWER_LATERALDataTable)assetSewerLateralGateway.Table)
                {
                    lfsAssetSewerLateral.DeleteDirect(rowLateral.AssetID, companyId);
                }

                // Get MHs for deleted
                AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                assetSewerSectionGateway.LoadByAssetId(assetId, companyId);
                int? usmh_assetId = assetSewerSectionGateway.GetUSMH(assetId);
                int? dsmh_assetId = assetSewerSectionGateway.GetDSMH(assetId);

                // Delete section
                LfsAssetSewerSectionGateway lfsAssetSewerSectionGateway = new LfsAssetSewerSectionGateway(null);
                lfsAssetSewerSectionGateway.Delete(assetId, companyId);

                LfsAssetSewer lfsAssetSewer = new LfsAssetSewer(null);
                lfsAssetSewer.DeleteDirect(assetId, companyId);

                LfsAsset lfsAsset = new LfsAsset(null);
                lfsAsset.DeleteDirect(assetId, companyId);

                // delete section in AM tables
                AssetSewerSection assetSewerSection = new AssetSewerSection(null);
                assetSewerSection.DeleteDirect(assetId, companyId);

                // Delete USMH (if not in use)
                if (usmh_assetId.HasValue)
                {
                    LfsAssetSewerMH lfsAssetSewerUsmh = new LfsAssetSewerMH(null);
                    lfsAssetSewerUsmh.DeleteDirect((int)usmh_assetId, companyId);
                }

                // Delete DSMH (if not in use)
                if (dsmh_assetId.HasValue)
                {
                    LfsAssetSewerMH lfsAssetSewerDsmh = new LfsAssetSewerMH(null);
                    lfsAssetSewerDsmh.DeleteDirect((int)dsmh_assetId, companyId);
                }

                return true;
            }
            else
            {
                return false;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="companyId">companyId</param>
        public void Delete(int workId, int companyId)
        {
            WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateway = new WorkFullLengthLiningM1LateralGateway();
            workFullLengthLiningM1LateralGateway.LoadByWorkId(workId, companyId);

            foreach (WorkTDS.LFS_WORK_FULLLENGTHLINING_M1_LATERALRow row in (WorkTDS.LFS_WORK_FULLLENGTHLINING_M1_LATERALDataTable)workFullLengthLiningM1LateralGateway.Table)
            {
                // delete lfs lateral client
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(workId, companyId);
                int currentProjectId = workGateway.GetProjectId(workId);

                ProjectGateway projectGateway = new ProjectGateway();
                projectGateway.LoadByProjectId(currentProjectId);
                int clientId = projectGateway.GetClientID(currentProjectId);

                LfsAssetSewerLateralClientGateway lfsAssetSewerLateralClientGateway = new LfsAssetSewerLateralClientGateway();
                lfsAssetSewerLateralClientGateway.LoadByAssetIdClientId(row.Lateral, clientId, companyId);

                if (lfsAssetSewerLateralClientGateway.Table.Rows.Count > 0)
                {
                    LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                    lfsAssetSewerLateralClient.DeleteDirect(row.Lateral, clientId, companyId);
                }

                // Delete work lateral
                workFullLengthLiningM1LateralGateway.Delete(workId, row.Lateral, companyId);

                // Delete section
                LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
                lfsAssetSewerLateral.DeleteDirect(row.Lateral, companyId);
            }
        }
        /// <summary>
        /// Save a JL Work
        /// </summary>
        /// <param name="originalId">originalId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="section_assetId">section_assetId</param>
        /// <param name="numLats">numLats</param>
        /// <param name="notLinedYet">notLinedYet</param>
        /// <param name="allMeasured">allMeasured</param>
        /// <param name="issueWithLaterals">issueWithLaterals</param>
        /// <param name="notMeasuredYet">notMeasuredYet</param>
        /// <param name="notDeliveredYet">notDeliveredYet</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        private void SaveJLWork(Guid originalId, int section_assetId, int numLats, int notLinedYet, bool allMeasured, string issueWithLaterals, int notMeasuredYet, int notDeliveredYet, int projectId, Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int companyId)
        {
            // Insert Junction Lining Section
            WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
            int sectionWorkId = workJunctionLiningSection.InsertDirect(projectId, section_assetId, null, numLats, notLinedYet, allMeasured, issueWithLaterals, notMeasuredYet, notDeliveredYet, false, companyId, "", "", "", "", false, "", 0);

            // Insert Junction Lining Laterals
            SectionTDS sectionTDS = new SectionTDS();

            SectionGateway sectionGateway = new SectionGateway(sectionTDS);
            sectionGateway.LoadById(originalId, companyId);

            JlinerGateway jlinerGateway = new JlinerGateway(sectionTDS);
            jlinerGateway.LoadByIdCompanyId(originalId, companyId);

            foreach (SectionTDS.LFS_JUNCTION_LINER2Row row in (SectionTDS.LFS_JUNCTION_LINER2DataTable)jlinerGateway.Table)
            {
                string lateralID = ""; if (!row.IsDetailIDNull()) lateralID = row.DetailID;
                string address = ""; if (!row.IsAddressNull()) address = row.Address;
                string distanceFromUSMH = ""; if (!row.IsDistanceFromUSMHNull()) distanceFromUSMH = row.DistanceFromUSMH.ToString();
                string distanceFromDSMH = ""; if (!row.IsDistanceFromDSMHNull()) distanceFromDSMH = row.DistanceFromDSMH.ToString();
                DateTime? pipeLocated = null; if (!row.IsPipeLocatedNull()) pipeLocated = row.PipeLocated;
                DateTime? servicesLocated = null; if (!row.IsServicesLocatedNull()) servicesLocated = row.ServicesLocated;
                DateTime? coInstalled = null; if (!row.IsCoInstalledNull()) coInstalled = row.CoInstalled;
                DateTime? backfilledConcrete = null; if (!row.IsBackfilledConcreteNull()) backfilledConcrete = row.BackfilledConcrete;
                DateTime? backfilledSoil = null; if (!row.IsBackfilledSoilNull()) backfilledSoil = row.BackfilledSoil;
                DateTime? grouted = null; if (!row.IsGroutedNull()) grouted = row.Grouted;
                DateTime? cored = null; if (!row.IsCoredNull()) cored = row.Cored;
                DateTime? prepped = null; if (!row.IsPreppedNull()) prepped = row.Prepped;
                DateTime? measured = null; if (!row.IsMeasuredNull()) measured = row.Measured;
                string linerSize = ""; if (!row.IsLinerSizeNull()) linerSize = row.LinerSize;
                DateTime? inProcess = null; if (!row.IsInProcessNull()) inProcess = row.InProcess;
                DateTime? inStock = null; if (!row.IsInStockNull()) inStock = row.InStock;
                DateTime? delivered = null; if (!row.IsDeliveredNull()) delivered = row.Delivered;
                int? buildRebuid = null; if (!row.IsBuildRebuildNull()) buildRebuid = row.BuildRebuild;
                DateTime? preVideo = null; if (!row.IsPreVideoNull()) preVideo = row.PreVideo;
                DateTime? linerInstalled = null; if (!row.IsLinerInstalledNull()) linerInstalled = row.LinerInstalled;
                DateTime? finalVideo = null; if (!row.IsFinalVideoNull()) finalVideo = row.FinalVideo;
                string map = ""; if (!row.IsMapNull()) map = row.Map;
                decimal? cost = null; if (!row.IsCostNull()) cost = row.Cost;
                DateTime? videoInspection = null; if (!row.IsVideoInspectionNull()) videoInspection = row.VideoInspection;
                bool coRequired = row.CoRequired;
                bool pitRequired = row.PitRequired;
                string coPitLocation = ""; if (!row.IsCoPitLocationNull()) coPitLocation = row.CoPitLocation;
                bool postContractDigRequired = row.PostContractDigRequired;
                string comments = ""; if (!row.IsCommentsNull()) comments = row.Comments;
                string history = ""; if (!row.IsHistoryNull()) history = row.History;
                DateTime? coCutDown = null; if (!row.IsCoCutDownNull()) coCutDown = row.CoCutDown;
                DateTime? finalRestoration = null; if (!row.IsFinalRestorationNull()) finalRestoration = row.FinalRestoration;
                string clientLateralId = ""; if (!row.IsClientLateralIDNull()) clientLateralId = row.ClientLateralID;
                string videoLengthToPropertyLine = ""; if (!row.IsVideoLengthToPropertyLineNull()) videoLengthToPropertyLine = row.VideoLengthToPropertyLine;
                bool liningThruCo = row.LiningThruCo;
                DateTime? noticeDelivered = null; if (!row.IsNoticeDeliveredNull()) noticeDelivered = row.NoticeDelivered;
                string hamiltonInspectionNumber = ""; if (!row.IsHamiltonInspectionNumberNull()) hamiltonInspectionNumber = row.HamiltonInspectionNumber;
                bool dyeTestReq = row.DyeTestReq;
                DateTime? dyeTestComplete = null; if (!row.IsDyeTestCompleteNull()) dyeTestComplete = row.DyeTestComplete;

                // Fields only presents in new Junction lining
                string flange = "";
                string gasket = "";
                string connectionType = "";
                string depthOfLocated = "";
                bool digRequiredPriorToLining = false;
                DateTime? digRequiredPriorToLiningCompleted = null;
                bool digRequiredAfterLining = false;
                DateTime? digRequiredAfterLiningCompleted = null;
                bool outOfScope = false;
                bool holdClientIssue = false;
                DateTime? holdClientIssueResolved  = null;
                bool holdLFSIssue = false;
                DateTime? holdLFSIssueResolved = null;
                bool requiresRoboticPrep = false;
                DateTime? requiresRoboticPrepCompleted = null;

                ProjectGateway projectGateway = new ProjectGateway();
                projectGateway.LoadByProjectId(projectId);
                int clientId = projectGateway.GetClientID(projectId);

                // Insert into LFS Asset Lateral
                LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
                int lateralAssetId = lfsAssetSewerLateral.InsertDirect(countryId, provinceId, countyId, cityId, section_assetId, address, lateralID, "", "", "", "", "Live", "", distanceFromUSMH, distanceFromDSMH, "", false, companyId, connectionType);

                // Insert into LFS Asset Lateral Client
                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                lfsAssetSewerLateralClient.InsertDirect(lateralAssetId, clientId, clientLateralId, false, companyId);

                // Insert into Work Junction Lining Lateral
                WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
                int workLateral = workJunctionLiningLateral.InsertDirect(projectId, lateralAssetId, sectionWorkId, pipeLocated, servicesLocated, coInstalled, backfilledConcrete, backfilledSoil, grouted, cored, prepped, measured, linerSize, inProcess, inStock, delivered, buildRebuid, preVideo, linerInstalled, finalVideo, cost, videoInspection, coRequired, pitRequired, coPitLocation, postContractDigRequired, coCutDown, finalRestoration, false, companyId, comments, history, videoLengthToPropertyLine, liningThruCo, noticeDelivered, hamiltonInspectionNumber, flange, gasket, depthOfLocated, digRequiredPriorToLining, digRequiredPriorToLiningCompleted, digRequiredAfterLining, digRequiredAfterLiningCompleted, outOfScope, holdClientIssue, holdClientIssueResolved, holdLFSIssue, holdLFSIssueResolved, requiresRoboticPrep, requiresRoboticPrepCompleted, "", "", dyeTestReq, dyeTestComplete, "");

                // Insert into Work Comments
                JlinerCommentGateway jlinerCommentGateway = new JlinerCommentGateway(sectionTDS);
                jlinerCommentGateway.LoadByIdRefId(originalId, row.RefID, companyId);

                foreach (SectionTDS.LFS_JUNCTION_LINER2_COMMENTRow rowComment in (SectionTDS.LFS_JUNCTION_LINER2_COMMENTDataTable)jlinerCommentGateway.Table)
                {
                    int loginId = rowComment.LoginID;
                    DateTime dateTime_ = rowComment.DateTime_;
                    string comment = rowComment.Comment;

                    WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
                    workCommentsGateway.LoadByWorkIdWorkType(workLateral, companyId, "Junction Lining Lateral");
                    WorkComments workComments = new WorkComments(workCommentsGateway.Data);
                    workComments.Insert(workLateral, 0, "Junction Lining Lateral", "Bulk Upload Comments", loginId, dateTime_, comment, null, false, companyId, false, "Junction Lining");

                    // Update Comments
                    workCommentsGateway.Update();
                }

                // Insert into Work History
                JlinerHistoryGateway jlinerHistoryGateway = new JlinerHistoryGateway(sectionTDS);
                jlinerHistoryGateway.LoadByIdRefId(originalId, row.RefID, companyId);

                foreach (SectionTDS.LFS_JUNCTION_LINER2_HISTORYRow rowHistory in (SectionTDS.LFS_JUNCTION_LINER2_HISTORYDataTable)jlinerHistoryGateway.Table)
                {
                    int loginId = rowHistory.LoginID;
                    DateTime dateTime_H = rowHistory.DateTime_;
                    string history_ = rowHistory.History;

                    WorkHistoryGateway workHistoryGateway = new WorkHistoryGateway();
                    workHistoryGateway.LoadByWorkIdWorkType(workLateral, companyId, "Junction Lining Lateral");
                    WorkHistory workHistory = new WorkHistory(workHistoryGateway.Data);
                    workHistory.Insert(workLateral, 0, "Junction Lining Lateral", "Bulk Upload History", loginId, dateTime_H, history_, null, false, companyId, false, "Junction Lining");

                    // Update History
                    workHistoryGateway.Update();
                }
            }
        }
        /// <summary>
        /// Save a lateral
        /// </summary>
        /// <param name="row">row</param>
        /// <param name="projectId">projectId</param>
        /// <param name="sectionAssetId">sectionAssetId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="isNewMeasuredFromDsmh">isNewMeasuredFromDsmh</param>
        /// <returns>lateral_assetId</returns>
        private int SaveLateral(FullLengthLiningTDS.LateralDetailsRow row, int projectId, int sectionAssetId, Int64 countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int companyId, bool isNewMeasuredFromDsmh)
        {
            int section_ = sectionAssetId;
            string lateralID = row.LateralID;

            if (!isNewMeasuredFromDsmh)
            {
                lateralID = lateralID.Substring(3, lateralID.Length - 3);
            }

            string address = ""; if (!row.IsMnNull()) address = row.Mn;
            string size_ = ""; if (!row.IsSize_Null()) size_ = row.Size_;
            string live = ""; if (!row.IsLiveNull()) live = row.Live;
            string distanceFromUSMH = ""; if (!row.IsDistanceFromUSMHNull()) distanceFromUSMH = row.DistanceFromUSMH;
            string distanceFromDSMH = ""; if (!row.IsDistanceFromDSMHNull()) distanceFromDSMH = row.DistanceFromDSMH;
            string connectionType = ""; if (!row.IsConnectionTypeNull()) connectionType = row.ConnectionType;

            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            int lateral_assetId = lfsAssetSewerLateral.InsertDirect(countryId, provinceId, countyId, cityId, section_, address, lateralID, "", "", "", "", live, size_, distanceFromUSMH, distanceFromDSMH, "", false, companyId, connectionType);

            return lateral_assetId;
        }
        /// <summary>
        /// Delete lateral work
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="lateral">lateral</param>
        /// <param name="companyId">companyId</param>
        /// <param name="projectId">projectId</param>
        private void DeleteFLLLateral(int workId, int lateral, int companyId, int projectId)
        {
            // Delete work lateral
            WorkFullLengthLiningM1Lateral workFullLengthLiningM1Lateral = new WorkFullLengthLiningM1Lateral(null);
            workFullLengthLiningM1Lateral.DeleteDirect(workId, lateral, companyId);

            // Delete section
            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            bool isDeleted = lfsAssetSewerLateral.DeleteDirect(lateral, companyId);

            if (isDeleted)
            {
                ProjectGateway projectGateway = new ProjectGateway();
                projectGateway.LoadByProjectId(projectId);
                int clientId = projectGateway.GetClientID(projectId);

                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                lfsAssetSewerLateralClient.DeleteDirect(lateral, clientId, companyId);
            }
        }
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="assetIdLateral">assetIdLateral</param>
        /// <param name="sectionWorkId">sectionWorkId</param>
        /// <param name="companyId">companyId</param>
        private void Delete(int workId, int assetIdLateral, int sectionWorkId, int companyId)
        {
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByWorkId(workId, companyId);
            int currentProjectId = workGateway.GetProjectId(workId);

            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(currentProjectId);
            int clientId = projectGateway.GetClientID(currentProjectId);

            // delete lateral work
            WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
            workJunctionLiningLateral.DeleteDirect(workId, sectionWorkId, companyId);

            // delete lfs lateral
            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            bool isDeleted = lfsAssetSewerLateral.DeleteDirect(assetIdLateral, companyId);

            if (isDeleted)
            {
                // delete lfs lateral client
                LfsAssetSewerLateralClientGateway lfsAssetSewerLateralClientGateway = new LfsAssetSewerLateralClientGateway();
                lfsAssetSewerLateralClientGateway.LoadByAssetIdClientId(assetIdLateral, clientId, companyId);

                if (lfsAssetSewerLateralClientGateway.Table.Rows.Count > 0)
                {
                    LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                    lfsAssetSewerLateralClient.DeleteDirect(assetIdLateral, clientId, companyId);
                }
            }
        }
        /// <summary>
        /// Delete lateral work
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="lateral">lateral</param>
        /// <param name="companyId">companyId</param>
        /// <param name="clientId">clientId</param>
        private void DeleteFLLLateral(int workId, int lateral, int companyId, int clientId)
        {
            // Delete work lateral
            WorkFullLengthLiningM1Lateral workFullLengthLiningM1Lateral = new WorkFullLengthLiningM1Lateral(null);
            workFullLengthLiningM1Lateral.DeleteDirect(workId, lateral, companyId);

            // Delete section
            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            bool isDeleted = lfsAssetSewerLateral.DeleteDirect(lateral, companyId);

            if (isDeleted)
            {
                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                lfsAssetSewerLateralClient.DeleteDirect(lateral, clientId, companyId);
            }
        }
        /// <summary>
        /// Save a lateral
        /// </summary>
        /// <param name="row">row</param>
        /// <param name="projectId">projectId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        /// <returns>lateral_assetId</returns>
        private int SaveLateral(JlAddLateralsTDS.JlAddLateralsTempRow row, int projectId, Int64 countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int companyId)
        {
            int section_ = row.SectionAssetID;
            string lateralID = row.LateralID;
            string address = ""; if (!row.IsAddressNull()) address = row.Address;
            string distanceFromUSMH = ""; if (!row.IsDistanceFromUSMHNull()) distanceFromUSMH = row.DistanceFromUSMH;
            string distanceFromDSMH = ""; if (!row.IsDistanceFromDSMHNull()) distanceFromDSMH = row.DistanceFromDSMH;

            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            int lateral_assetId = lfsAssetSewerLateral.InsertDirect(countryId, provinceId, countyId, cityId, row.SectionAssetID, address, lateralID, "", "", "", "", "Live", "", distanceFromUSMH, distanceFromDSMH, "", false, companyId, "");

            return lateral_assetId;
        }