/// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        public bool DeleteDirect(int assetId, int companyId)
        {
            // Delete laterals
            // ... Define initial models
            AssetSewerLateral assetSewerLateral = new AssetSewerLateral(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)
            {
                assetSewerLateral.DeleteDirect(rowLateral.AssetID, companyId);
            }

            // Delete section
            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway(null);
            assetSewerSectionGateway.Delete(assetId, companyId);

            AssetSewer assetSewer = new AssetSewer(null);
            assetSewer.DeleteDirect(assetId, companyId);

            Asset asset = new Asset(null);
            asset.DeleteDirect(assetId, companyId);

            return true;
        }
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        public bool DeleteDirect(int assetId, int companyId)
        {
            // Get initial data
            AssetSewerLateralGateway assetSewerLateralGateway = new AssetSewerLateralGateway();
            assetSewerLateralGateway.LoadByAssetId(assetId, companyId);
            int section_ = assetSewerLateralGateway.GetSection(assetId);
            string state = assetSewerLateralGateway.GetState(assetId);

            // Delete lateral
            assetSewerLateralGateway.Delete(assetId, companyId);
            AssetSewer assetSewer = new AssetSewer(null);
            assetSewer.DeleteDirect(assetId, companyId);
            Asset asset = new Asset(null);
            asset.DeleteDirect(assetId, companyId);

            // Update Section
            // ... Load section
            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
            assetSewerSectionGateway.LoadByAssetId(section_, companyId);

            // ... Get old values of section
            string sectionIdS = assetSewerSectionGateway.GetSectionId(section_);
            string streetS = assetSewerSectionGateway.GetStreet(section_);
            int? usmhIdS = assetSewerSectionGateway.GetUSMH(section_);
            int? dsmhIdS = assetSewerSectionGateway.GetDSMH(section_);
            string mapSizeS = assetSewerSectionGateway.GetMapSize(section_);
            string size_S = assetSewerSectionGateway.GetSize_(section_);
            string mapLengthS = assetSewerSectionGateway.GetMapSize(section_);
            string lengthS = assetSewerSectionGateway.GetLength(section_);
            int? lateralsS = assetSewerSectionGateway.GetLaterals(section_);
            int? liveLateralsS = assetSewerSectionGateway.GetLiveLaterals(section_);
            string flowDirectionS = assetSewerSectionGateway.GetFlowDirection(section_);
            string usmhDepthS = assetSewerSectionGateway.GetUSMHDepth(section_);
            string dsmhDepthS = assetSewerSectionGateway.GetDSMHDepth(section_);
            bool deletedS = assetSewerSectionGateway.GetDeleted(section_);
            string flowOrderIdS = assetSewerSectionGateway.GetFlowOrderID(section_);

            // ... Calculate new values of section
            int? newLaterals = lateralsS - 1;

            int? newLiveLaterals = liveLateralsS;
            if ((newLiveLaterals.HasValue) && (state == "Live"))
            {
                newLiveLaterals = newLiveLaterals - 1;
            }

            // ... Update section
            AssetSewerSection assetSewerSection = new AssetSewerSection(assetSewerSectionGateway.Data);
            assetSewerSection.UpdateDirect(section_, sectionIdS, streetS, usmhIdS, dsmhIdS, mapSizeS, size_S, mapLengthS, lengthS, lateralsS, liveLateralsS, flowDirectionS, usmhDepthS, dsmhDepthS, deletedS, companyId, flowOrderIdS, section_, sectionIdS, streetS, usmhIdS, dsmhIdS, mapSizeS, size_S, mapLengthS, lengthS, newLaterals, newLiveLaterals, flowDirectionS, usmhDepthS, dsmhDepthS, deletedS, companyId, flowOrderIdS);

            return true;
        }
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        public bool DeleteDirect(int assetId, int companyId)
        {
            if (!InUse(assetId, companyId))
            {
                AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway(null);
                assetSewerMhGateway.Delete(assetId, companyId);

                AssetSewer assetSewer = new AssetSewer(null);
                assetSewer.DeleteDirect(assetId, companyId);

                Asset asset = new Asset(null);
                asset.DeleteDirect(assetId, companyId);

                return true;
            }
            else
            {
                return false;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// InsertDirect
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="mhid">mhid</param>
        /// <param name="latitude">latitude</param>
        /// <param name="longitude">longitude</param>
        /// <param name="address">address</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="manholeShape">manholeShape</param>
        /// <param name="location">location</param>
        /// <param name="materialID">materialID</param>
        /// <param name="topDiameter">topDiameter</param>
        /// <param name="topDepth">topDepth</param>
        /// <param name="topFloor">topFloor</param>
        /// <param name="topCeiling">topCeiling</param>
        /// <param name="topBenching">topBenching</param>
        /// <param name="downDiameter">downDiameter</param>
        /// <param name="downDepth">downDepth</param>
        /// <param name="downFloor">downFloor</param>
        /// <param name="downCeiling">downCeiling</param>
        /// <param name="downBenching">downBenching</param>
        /// <param name="rectangle1LongSide">rectangle1LongSide</param>
        /// <param name="rectangle1ShortSide">rectangle1ShortSide</param>
        /// <param name="rectangle2LongSide">rectangle2LongSide</param>
        /// <param name="rectangle2ShortSide">rectangle2ShortSide</param>
        /// <param name="topSurfaceArea">topSurfaceArea</param>
        /// <param name="downSurfaceArea">downSurfaceArea</param>
        /// <param name="manholeRugs">manholeRugs</param>
        /// <param name="totalDepth">totalDepth</param>
        /// <param name="totalSurfaceArea">totalSurfaceArea</param>
        public int InsertDirect(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, string mhid, string latitude, string longitude, string address, bool deleted, int companyId, string manholeShape, string location, int? materialID, string topDiameter, string topDepth, string topFloor, string topCeiling, string topBenching, string downDiameter, string downDepth, string downFloor, string downCeiling, string downBenching, string rectangle1LongSide, string rectangle1ShortSide, string rectangle2LongSide, string rectangle2ShortSide, string topSurfaceArea, string downSurfaceArea, int? manholeRugs, string totalDepth, string totalSurfaceArea)
        {
            AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway();
            assetSewerMhGateway.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, mhid, companyId, latitude, longitude, address);
            int mh_assetId = 0;

            if (assetSewerMhGateway.Table.Rows.Count == 0)
            {
                mh_assetId = new Asset(new DataSet()).InsertDirect("Sewer", countryId, provinceId, countyId, cityId, deleted, companyId);
                new AssetSewer(new DataSet()).InsertDirect(mh_assetId, "MH", deleted, companyId);
                assetSewerMhGateway.Insert(mh_assetId, mhid, latitude, longitude, address, deleted, companyId, manholeShape, location, materialID, topDiameter, topDepth, topFloor, topCeiling, topBenching, downDiameter, downDepth, downFloor, downCeiling, downBenching, rectangle1LongSide, rectangle1ShortSide, rectangle2LongSide, rectangle2ShortSide, topSurfaceArea, downSurfaceArea, manholeRugs, totalDepth, totalSurfaceArea);

            }
            else
            {
                mh_assetId = assetSewerMhGateway.GetAssetID(mhid);
            }

            return mh_assetId;
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// InsertDirect
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="sectionId">sectionId</param>
        /// <param name="street">street</param>
        /// <param name="usmh">usmh</param>
        /// <param name="dsmh">dsmh</param>
        /// <param name="mapSize">mapSize</param>
        /// <param name="size">size</param>
        /// <param name="mapLength">mapLength</param>
        /// <param name="length">length</param>
        /// <param name="laterals">laterals</param>
        /// <param name="liveLaterals">liveLaterals</param>
        /// <param name="flowDirections">flowDirections</param>
        /// <param name="usmhDepth">usmhDepth</param>
        /// <param name="dsmhDepth">dsmhDepth</param>
        /// <param name="usmhAddress">usmhAddress</param>
        /// <param name="dsmhAddress">dsmhAddress</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="flowOrderId">flowOrderId</param>
        /// <returns>section_assetId</returns>
        public int InsertDirect(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, string sectionId, string street, int? usmh, int? dsmh, string mapSize, string size, string mapLength, string length, int? laterals, int? liveLaterals, string flowDirections, string usmhDepth, string dsmhDepth, string usmhAddress, string dsmhAddress, bool deleted, int companyId, string flowOrderId)
        {
            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
            assetSewerSectionGateway.LoadByCountryIdProvinceIdCountyIdCityIdSectionId(countryId, provinceId, countyId, cityId, sectionId, companyId);

            int section_assetId = 0;
            if (assetSewerSectionGateway.Table.Rows.Count == 0)
            {
                section_assetId = new Asset(new DataSet()).InsertDirect("Sewer", countryId, provinceId, countyId, cityId, deleted, companyId);
                new AssetSewer(new DataSet()).InsertDirect(section_assetId, "Section", deleted, companyId);
                assetSewerSectionGateway.Insert(section_assetId, sectionId, street, usmh, dsmh, mapSize, size, mapLength, length, laterals, liveLaterals, flowDirections, usmhDepth, dsmhDepth, deleted, companyId, flowOrderId);
            }
            else
            {
                section_assetId = assetSewerSectionGateway.GetAssetID(sectionId);
            }

            return section_assetId;
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// InsertDirect
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="section_">section_</param>
        /// <param name="address">address</param>
        /// <param name="lateralID">lateralID</param>
        /// <param name="latitudeAtSection">latitudeAtSection</param>
        /// <param name="longitudeAtSection">longitudeAtSection</param>
        /// <param name="latitudeAtPropertyLine">latitudeAtPropertyLine</param>
        /// <param name="longitudeAtPropertyLine">longitudeAtPropertyLine</param>
        /// <param name="state">state</param>
        /// <param name="size_">size_</param>
        /// <param name="distanceFromUSMH">distanceFromUSMH</param>
        /// <param name="distanceFromDSMH">distanceFromDSMH</param>
        /// <param name="mapSize">mapSize</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="connectionType">connectionType</param>
        /// <returns></returns>
        public int InsertDirect(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int section_, string address, string lateralID, string latitudeAtSection, string longitudeAtSection, string latitudeAtPropertyLine, string longitudeAtPropertyLine, string state, string size_, string distanceFromUSMH, string distanceFromDSMH, string mapSize, bool deleted, int companyId, string connectionType)
        {
            AssetSewerLateralGateway assetSewerLateralGateway = new AssetSewerLateralGateway();
            assetSewerLateralGateway.LoadBySectionLateralId(section_, lateralID, companyId);

            int lateral_assetId = 0;
            if (assetSewerLateralGateway.Table.Rows.Count == 0)
            {
                // Insert Asset
                lateral_assetId = new Asset(new DataSet()).InsertDirect("Sewer", countryId, provinceId, countyId, cityId, deleted, companyId);
                new AssetSewer(new DataSet()).InsertDirect(lateral_assetId, "Lateral", deleted, companyId);
                assetSewerLateralGateway.Insert(lateral_assetId, section_, address, lateralID, latitudeAtSection, longitudeAtSection, latitudeAtPropertyLine, longitudeAtPropertyLine, state, size_, distanceFromUSMH, distanceFromDSMH, mapSize, deleted, companyId, connectionType);

                // Update Section
                // ... load section
                AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                assetSewerSectionGateway.LoadByAssetId(section_, companyId);

                // ... get old values of section
                string sectionIdS = assetSewerSectionGateway.GetSectionId(section_);
                string streetS = assetSewerSectionGateway.GetStreet(section_);
                int? usmhIdS = assetSewerSectionGateway.GetUSMH(section_);
                int? dsmhIdS = assetSewerSectionGateway.GetDSMH(section_);
                string mapSizeS = assetSewerSectionGateway.GetMapSize(section_);
                string size_S = assetSewerSectionGateway.GetSize_(section_);
                string mapLengthS = assetSewerSectionGateway.GetMapSize(section_);
                string lengthS = assetSewerSectionGateway.GetLength(section_);
                int? lateralsS = assetSewerSectionGateway.GetLaterals(section_);
                int? liveLateralsS = assetSewerSectionGateway.GetLiveLaterals(section_);
                string flowDirectionS = assetSewerSectionGateway.GetFlowDirection(section_);
                string usmhDepthS = assetSewerSectionGateway.GetUSMHDepth(section_);
                string dsmhDepthS = assetSewerSectionGateway.GetDSMHDepth(section_);
                string flowOrderIdS = assetSewerSectionGateway.GetFlowOrderID(section_);

                // ... calculate new values of section
                int? newLaterals  = lateralsS;
                if (newLaterals.HasValue)
                {
                    newLaterals = newLaterals + 1;
                }
                else
                {
                    newLaterals = 1;
                }

                int? newLiveLaterals = liveLateralsS;
                if (state == "Live")
                {
                    if (newLiveLaterals.HasValue)
                    {
                        newLiveLaterals = newLiveLaterals + 1;
                    }
                    else
                    {
                        newLiveLaterals = 1;
                    }
                }
                else
                {
                    newLiveLaterals = 0;
                }

                // ... update section
                AssetSewerSection assetSewerSection = new AssetSewerSection(assetSewerSectionGateway.Data);
                assetSewerSection.UpdateDirect(section_, sectionIdS, streetS, usmhIdS, dsmhIdS, mapSizeS, size_S, mapLengthS, lengthS, lateralsS, liveLateralsS, flowDirectionS, usmhDepthS, dsmhDepthS, deleted, companyId, flowOrderIdS, section_, sectionIdS, streetS, usmhIdS, dsmhIdS, mapSizeS, size_S, mapLengthS, lengthS, newLaterals, newLiveLaterals, flowDirectionS, usmhDepthS, dsmhDepthS, deleted, companyId, flowOrderIdS);
            }
            else
            {
                lateral_assetId = assetSewerLateralGateway.GetAssetID(section_, lateralID);
            }

            return lateral_assetId;
        }