protected static FR_L5BD_GBFRP_1436_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5BD_GBFRP_1436 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5BD_GBFRP_1436_Array();

            List <L5BD_GBFRP_1436> resultList = new List <L5BD_GBFRP_1436>();

            List <ORM_RES_BLD_Building> builidingList = new List <ORM_RES_BLD_Building>();

            ORM_RES_BLD_Building_RevisionHeader.Query rhQuery = new ORM_RES_BLD_Building_RevisionHeader.Query();
            rhQuery.IsDeleted                = false;
            rhQuery.Tenant_RefID             = securityTicket.TenantID;
            rhQuery.RealestateProperty_RefID = Parameter.RealestatePropertyID;
            List <ORM_RES_BLD_Building_RevisionHeader> revisionHeaderList = ORM_RES_BLD_Building_RevisionHeader.Query.Search(Connection, Transaction, rhQuery);
            foreach (var revisionHeader in revisionHeaderList)
            {
                ORM_RES_BLD_Building bdQuery = new ORM_RES_BLD_Building();
                L5BD_GBFRP_1436      item    = new L5BD_GBFRP_1436();

                ORM_RES_BLD_Building building = new ORM_RES_BLD_Building();
                building.Load(Connection, Transaction, revisionHeader.CurrentBuildingVersion_RefID);

                ORM_RES_BLD_Apartment.Query apQuery = new ORM_RES_BLD_Apartment.Query();
                apQuery.Tenant_RefID   = securityTicket.TenantID;
                apQuery.IsDeleted      = false;
                apQuery.Building_RefID = building.RES_BLD_BuildingID;
                item.appartmentCount   = ORM_RES_BLD_Apartment.Query.Search(Connection, Transaction, apQuery).ToArray().Length;

                ORM_RES_BLD_Attic.Query atQuery = new ORM_RES_BLD_Attic.Query();
                atQuery.Tenant_RefID   = securityTicket.TenantID;
                atQuery.IsDeleted      = false;
                atQuery.Building_RefID = building.RES_BLD_BuildingID;
                item.atticsCount       = ORM_RES_BLD_Attic.Query.Search(Connection, Transaction, atQuery).ToArray().Length;

                ORM_RES_BLD_Basement.Query baQuery = new ORM_RES_BLD_Basement.Query();
                baQuery.Tenant_RefID   = securityTicket.TenantID;
                baQuery.IsDeleted      = false;
                baQuery.Building_RefID = building.RES_BLD_BuildingID;
                item.basementsCount    = ORM_RES_BLD_Basement.Query.Search(Connection, Transaction, baQuery).ToArray().Length;

                ORM_RES_BLD_Facade.Query faQuery = new ORM_RES_BLD_Facade.Query();
                faQuery.Tenant_RefID   = securityTicket.TenantID;
                faQuery.IsDeleted      = false;
                faQuery.Building_RefID = building.RES_BLD_BuildingID;
                item.facadesCount      = ORM_RES_BLD_Facade.Query.Search(Connection, Transaction, faQuery).ToArray().Length;

                ORM_RES_BLD_HVACR.Query hvQuery = new ORM_RES_BLD_HVACR.Query();
                hvQuery.Tenant_RefID   = securityTicket.TenantID;
                hvQuery.IsDeleted      = false;
                hvQuery.Building_RefID = building.RES_BLD_BuildingID;
                item.hvarcsCount       = ORM_RES_BLD_HVACR.Query.Search(Connection, Transaction, hvQuery).ToArray().Length;

                ORM_RES_BLD_OutdoorFacility.Query ofQuery = new ORM_RES_BLD_OutdoorFacility.Query();
                ofQuery.Tenant_RefID        = securityTicket.TenantID;
                ofQuery.IsDeleted           = false;
                ofQuery.Building_RefID      = building.RES_BLD_BuildingID;
                item.outdoorfacilitiesCount = ORM_RES_BLD_OutdoorFacility.Query.Search(Connection, Transaction, ofQuery).ToArray().Length;

                ORM_RES_BLD_Roof.Query roQuery = new ORM_RES_BLD_Roof.Query();
                roQuery.Tenant_RefID   = securityTicket.TenantID;
                roQuery.IsDeleted      = false;
                roQuery.Building_RefID = building.RES_BLD_BuildingID;
                item.roofCount         = ORM_RES_BLD_Roof.Query.Search(Connection, Transaction, roQuery).ToArray().Length;

                ORM_RES_BLD_Staircase.Query stQuery = new ORM_RES_BLD_Staircase.Query();
                stQuery.Tenant_RefID   = securityTicket.TenantID;
                stQuery.IsDeleted      = false;
                stQuery.Building_RefID = building.RES_BLD_BuildingID;
                item.staircasesCount   = ORM_RES_BLD_Staircase.Query.Search(Connection, Transaction, stQuery).ToArray().Length;

                item.Building_Name      = building.Building_Name;
                item.RES_BLD_BuildingID = building.RES_BLD_BuildingID;
                resultList.Add(item);
            }

            returnValue.Result = resultList.ToArray();
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5BD_GBFB_1408 Execute(DbConnection Connection, DbTransaction Transaction, P_L5BD_GBFB_1408 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5BD_GBFB_1408();

            returnValue.Result = new L5BD_GBFB_1408();

            ORM_RES_BLD_Building building = new ORM_RES_BLD_Building();
            building.Load(Connection, Transaction, Parameter.BuildingID);

            returnValue.Result.Building_BalconyPortionPercent        = building.Building_BalconyPortionPercent;
            returnValue.Result.Building_DocumentationStructure_RefID = building.Building_DocumentationStructure_RefID;
            returnValue.Result.Building_ElevatorCoveragePercent      = building.Building_ElevatorCoveragePercent;
            returnValue.Result.Building_Name = building.Building_Name;
            returnValue.Result.Building_NumberOfAppartments         = building.Building_NumberOfAppartments;
            returnValue.Result.Building_NumberOfFloors              = building.Building_NumberOfFloors;
            returnValue.Result.Building_NumberOfOccupiedAppartments = building.Building_NumberOfOccupiedAppartments;
            returnValue.Result.Building_NumberOfOffices             = building.Building_NumberOfOffices;
            returnValue.Result.Building_NumberOfOtherUnits          = building.Building_NumberOfOtherUnits;
            returnValue.Result.Building_NumberOfProductionUnits     = building.Building_NumberOfProductionUnits;
            returnValue.Result.Building_NumberOfRetailUnits         = building.Building_NumberOfRetailUnits;
            returnValue.Result.IsContaminationSuspected             = building.IsContaminationSuspected;
            returnValue.Result.RES_BLD_BuildingID = building.RES_BLD_BuildingID;


            ORM_RES_BLD_Apartment.Query apQuery = new ORM_RES_BLD_Apartment.Query();
            apQuery.Tenant_RefID               = securityTicket.TenantID;
            apQuery.IsDeleted                  = false;
            apQuery.Building_RefID             = building.RES_BLD_BuildingID;
            returnValue.Result.AppartmentCount = ORM_RES_BLD_Apartment.Query.Search(Connection, Transaction, apQuery).ToArray().Length;

            ORM_RES_BLD_Attic.Query atQuery = new ORM_RES_BLD_Attic.Query();
            atQuery.Tenant_RefID           = securityTicket.TenantID;
            atQuery.IsDeleted              = false;
            atQuery.Building_RefID         = building.RES_BLD_BuildingID;
            returnValue.Result.atticsCount = ORM_RES_BLD_Attic.Query.Search(Connection, Transaction, atQuery).ToArray().Length;

            ORM_RES_BLD_Basement.Query baQuery = new ORM_RES_BLD_Basement.Query();
            baQuery.Tenant_RefID              = securityTicket.TenantID;
            baQuery.IsDeleted                 = false;
            baQuery.Building_RefID            = building.RES_BLD_BuildingID;
            returnValue.Result.basementsCount = ORM_RES_BLD_Basement.Query.Search(Connection, Transaction, baQuery).ToArray().Length;

            ORM_RES_BLD_Facade.Query faQuery = new ORM_RES_BLD_Facade.Query();
            faQuery.Tenant_RefID            = securityTicket.TenantID;
            faQuery.IsDeleted               = false;
            faQuery.Building_RefID          = building.RES_BLD_BuildingID;
            returnValue.Result.facadesCount = ORM_RES_BLD_Facade.Query.Search(Connection, Transaction, faQuery).ToArray().Length;

            ORM_RES_BLD_HVACR.Query hvQuery = new ORM_RES_BLD_HVACR.Query();
            hvQuery.Tenant_RefID           = securityTicket.TenantID;
            hvQuery.IsDeleted              = false;
            hvQuery.Building_RefID         = building.RES_BLD_BuildingID;
            returnValue.Result.hvarcsCount = ORM_RES_BLD_HVACR.Query.Search(Connection, Transaction, hvQuery).ToArray().Length;

            ORM_RES_BLD_OutdoorFacility.Query ofQuery = new ORM_RES_BLD_OutdoorFacility.Query();
            ofQuery.Tenant_RefID   = securityTicket.TenantID;
            ofQuery.IsDeleted      = false;
            ofQuery.Building_RefID = building.RES_BLD_BuildingID;
            returnValue.Result.outdoorfacilitiesCount = ORM_RES_BLD_OutdoorFacility.Query.Search(Connection, Transaction, ofQuery).ToArray().Length;

            ORM_RES_BLD_Roof.Query roQuery = new ORM_RES_BLD_Roof.Query();
            roQuery.Tenant_RefID         = securityTicket.TenantID;
            roQuery.IsDeleted            = false;
            roQuery.Building_RefID       = building.RES_BLD_BuildingID;
            returnValue.Result.roofCount = ORM_RES_BLD_Roof.Query.Search(Connection, Transaction, roQuery).ToArray().Length;

            ORM_RES_BLD_Staircase.Query stQuery = new ORM_RES_BLD_Staircase.Query();
            stQuery.Tenant_RefID               = securityTicket.TenantID;
            stQuery.IsDeleted                  = false;
            stQuery.Building_RefID             = building.RES_BLD_BuildingID;
            returnValue.Result.staircasesCount = ORM_RES_BLD_Staircase.Query.Search(Connection, Transaction, stQuery).ToArray().Length;

            ORM_RES_BLD_Building_2_GarbageContainerType.Query gctQuery = new ORM_RES_BLD_Building_2_GarbageContainerType.Query();
            gctQuery.Tenant_RefID           = securityTicket.TenantID;
            gctQuery.IsDeleted              = false;
            gctQuery.RES_BLD_Building_RefID = building.RES_BLD_BuildingID;
            List <ORM_RES_BLD_Building_2_GarbageContainerType> garbageContainerType = ORM_RES_BLD_Building_2_GarbageContainerType.Query.Search(Connection, Transaction, gctQuery);
            returnValue.Result.RES_BLD_GarbageContainerTypeID = garbageContainerType[0].RES_BLD_GarbageContainerType_RefID;

            ORM_RES_BLD_Building_2_BuildingType.Query bdQuery = new ORM_RES_BLD_Building_2_BuildingType.Query();
            bdQuery.Tenant_RefID           = securityTicket.TenantID;
            bdQuery.IsDeleted              = false;
            bdQuery.RES_BLD_Building_RefID = building.RES_BLD_BuildingID;
            List <ORM_RES_BLD_Building_2_BuildingType> buildingType = ORM_RES_BLD_Building_2_BuildingType.Query.Search(Connection, Transaction, bdQuery);
            returnValue.Result.RES_BLD_Building_TypeID = buildingType[0].RES_BLD_Building_Type_RefID;

            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 3
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5BD_SB_1359 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var  returnValue   = new FR_Guid();
            bool editedVersion = false;

            ORM_RES_BLD_Building building = new ORM_RES_BLD_Building();
            if (Parameter.RES_BLD_BuildingID != Guid.Empty)
            {
                var result = building.Load(Connection, Transaction, Parameter.RES_BLD_BuildingID);
                if (result.Status != FR_Status.Success || building.RES_BLD_BuildingID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }

                List <ORM_RES_DUD_Revision> revisions = new List <ORM_RES_DUD_Revision>();
                revisions = ORM_RES_DUD_Revision.Query.Search(Connection, Transaction, new ORM_RES_DUD_Revision.Query()
                {
                    RES_BLD_Building_RefID = Parameter.RES_BLD_BuildingID,
                    Tenant_RefID           = securityTicket.TenantID,
                    IsDeleted = false
                });

                if (revisions.Count > 0)
                {
                    //building is connected to revision. create new with same properties if IsBuildingForEdit returns 0.
                    if (IsBuildingForEdit(Connection, Transaction, Parameter, building, securityTicket) == 0)
                    {
                        building      = new ORM_RES_BLD_Building();
                        editedVersion = true;
                    }
                    else
                    {
                        var noEdit = new FR_Guid();
                        noEdit.ErrorMessage = "No need to be edited.";
                        noEdit.Status       = FR_Status.Success;
                        return(noEdit);
                    }
                }
            }

            if (building.BuildingRevisionHeader_RefID == Guid.Empty)
            {
                ORM_RES_BLD_Building_RevisionHeader revisionHeader = new ORM_RES_BLD_Building_RevisionHeader();
                revisionHeader.RES_BLD_Building_RevisionHeaderID = Guid.NewGuid();
                revisionHeader.CurrentBuildingVersion_RefID      = building.RES_BLD_BuildingID;
                revisionHeader.RealestateProperty_RefID          = Parameter.RealestatePropertyID;
                revisionHeader.Tenant_RefID = securityTicket.TenantID;
                revisionHeader.Save(Connection, Transaction);
                building.BuildingRevisionHeader_RefID = revisionHeader.RES_BLD_Building_RevisionHeaderID;

                ORM_DOC_Structure_Header structureHeader = new ORM_DOC_Structure_Header();
                structureHeader.Save(Connection, Transaction);
                building.Building_DocumentationStructure_RefID = structureHeader.DOC_Structure_HeaderID;
            }

            building.Building_BalconyPortionPercent = Parameter.Building_BalconyPortionPercent;

            //if building is connected with revision, copied building has to have different name.
            building.Building_Name = editedVersion ? Parameter.Building_Name + " edit" : Parameter.Building_Name;

            building.IsContaminationSuspected             = Parameter.IsContaminationSuspected;
            building.Building_NumberOfFloors              = Parameter.Building_NumberOfFloors;
            building.Building_ElevatorCoveragePercent     = Parameter.Building_ElevatorCoveragePercent;
            building.Building_NumberOfAppartments         = Parameter.Building_NumberOfAppartments;
            building.Building_NumberOfOccupiedAppartments = Parameter.Building_NumberOfOccupiedAppartments;
            building.Building_NumberOfOffices             = Parameter.Building_NumberOfOffices;
            building.Building_NumberOfRetailUnits         = Parameter.Building_NumberOfRetailUnits;
            building.Building_NumberOfProductionUnits     = Parameter.Building_NumberOfProductionUnits;
            building.Building_NumberOfOtherUnits          = Parameter.Building_NumberOfOtherUnits;
            building.Tenant_RefID = securityTicket.TenantID;
            building.Save(Connection, Transaction);

            ORM_RES_BLD_Building_2_GarbageContainerType.Query build2GarbQuery = new ORM_RES_BLD_Building_2_GarbageContainerType.Query();
            build2GarbQuery.RES_BLD_Building_RefID = building.RES_BLD_BuildingID;
            build2GarbQuery.Tenant_RefID           = securityTicket.TenantID;
            List <ORM_RES_BLD_Building_2_GarbageContainerType> buildingsToGarbage = ORM_RES_BLD_Building_2_GarbageContainerType.Query.Search(Connection, Transaction, build2GarbQuery);

            if (buildingsToGarbage.Count != 0)
            {
                ORM_RES_BLD_Building_2_GarbageContainerType garbage = buildingsToGarbage[0];
                garbage.RES_BLD_GarbageContainerType_RefID = Parameter.RES_BLD_GarbageContainerTypeID;
                garbage.Save(Connection, Transaction);
            }
            else
            {
                ORM_RES_BLD_Building_2_GarbageContainerType garbage = new ORM_RES_BLD_Building_2_GarbageContainerType();
                garbage.RES_BLD_GarbageContainerType_RefID = Parameter.RES_BLD_GarbageContainerTypeID;
                garbage.RES_BLD_Building_RefID             = building.RES_BLD_BuildingID;
                garbage.Tenant_RefID = securityTicket.TenantID;
                garbage.Save(Connection, Transaction);
            }

            ORM_RES_BLD_Building_2_BuildingType.Query buildTypeQuery = new ORM_RES_BLD_Building_2_BuildingType.Query();
            buildTypeQuery.RES_BLD_Building_RefID = building.RES_BLD_BuildingID;
            buildTypeQuery.Tenant_RefID           = securityTicket.TenantID;
            List <ORM_RES_BLD_Building_2_BuildingType> buildingsType = ORM_RES_BLD_Building_2_BuildingType.Query.Search(Connection, Transaction, buildTypeQuery);

            if (buildingsType.Count != 0)
            {
                ORM_RES_BLD_Building_2_BuildingType buildingType = buildingsType[0];
                buildingType.RES_BLD_Building_Type_RefID = Parameter.RES_BLD_Building_TypeID;
                buildingType.RES_BLD_Building_RefID      = building.RES_BLD_BuildingID;
                buildingType.Save(Connection, Transaction);
            }
            else
            {
                ORM_RES_BLD_Building_2_BuildingType buildingType = new ORM_RES_BLD_Building_2_BuildingType();
                buildingType.RES_BLD_Building_RefID      = building.RES_BLD_BuildingID;
                buildingType.RES_BLD_Building_Type_RefID = Parameter.RES_BLD_Building_TypeID;
                buildingType.Tenant_RefID = securityTicket.TenantID;
                buildingType.Save(Connection, Transaction);
            }

            if (Parameter.RES_BLD_BuildingID == Guid.Empty || editedVersion)
            {
                for (int i = 0; i < Parameter.AppartmentCount; i++)
                {
                    ORM_RES_BLD_Apartment newAppartment = new ORM_RES_BLD_Apartment();
                    newAppartment.Building_RefID = building.RES_BLD_BuildingID;
                    newAppartment.Tenant_RefID   = securityTicket.TenantID;
                    newAppartment.Save(Connection, Transaction);
                }

                for (int i = 0; i < Parameter.staircasesCount; i++)
                {
                    ORM_RES_BLD_Staircase newStaircase = new ORM_RES_BLD_Staircase();
                    newStaircase.Building_RefID = building.RES_BLD_BuildingID;
                    newStaircase.Tenant_RefID   = securityTicket.TenantID;
                    newStaircase.Save(Connection, Transaction);
                }

                for (int i = 0; i < Parameter.outdoorfacilitiesCount; i++)
                {
                    ORM_RES_BLD_OutdoorFacility newOutdoorfacility = new ORM_RES_BLD_OutdoorFacility();
                    newOutdoorfacility.Building_RefID = building.RES_BLD_BuildingID;
                    newOutdoorfacility.Tenant_RefID   = securityTicket.TenantID;
                    newOutdoorfacility.Save(Connection, Transaction);
                }

                for (int i = 0; i < Parameter.facadesCount; i++)
                {
                    ORM_RES_BLD_Facade newFacade = new ORM_RES_BLD_Facade();
                    newFacade.Building_RefID = building.RES_BLD_BuildingID;
                    newFacade.Tenant_RefID   = securityTicket.TenantID;
                    newFacade.Save(Connection, Transaction);
                }

                for (int i = 0; i < Parameter.roofCount; i++)
                {
                    ORM_RES_BLD_Roof newRoof = new ORM_RES_BLD_Roof();
                    newRoof.Building_RefID = building.RES_BLD_BuildingID;
                    newRoof.Tenant_RefID   = securityTicket.TenantID;
                    newRoof.Save(Connection, Transaction);
                }

                for (int i = 0; i < Parameter.atticsCount; i++)
                {
                    ORM_RES_BLD_Attic newAttic = new ORM_RES_BLD_Attic();
                    newAttic.Building_RefID = building.RES_BLD_BuildingID;
                    newAttic.Tenant_RefID   = securityTicket.TenantID;
                    newAttic.Save(Connection, Transaction);
                }

                for (int i = 0; i < Parameter.basementsCount; i++)
                {
                    ORM_RES_BLD_Basement newBasement = new ORM_RES_BLD_Basement();
                    newBasement.Building_RefID = building.RES_BLD_BuildingID;
                    newBasement.Tenant_RefID   = securityTicket.TenantID;
                    newBasement.Save(Connection, Transaction);
                }

                for (int i = 0; i < Parameter.hvarcsCount; i++)
                {
                    ORM_RES_BLD_HVACR newHvacr = new ORM_RES_BLD_HVACR();
                    newHvacr.Building_RefID = building.RES_BLD_BuildingID;
                    newHvacr.Tenant_RefID   = securityTicket.TenantID;
                    newHvacr.Save(Connection, Transaction);
                }
            }
            else
            {
                ORM_RES_BLD_Apartment.Query appartmentQuery = new ORM_RES_BLD_Apartment.Query();
                appartmentQuery.Building_RefID = Parameter.RES_BLD_BuildingID;
                appartmentQuery.Tenant_RefID   = securityTicket.TenantID;
                appartmentQuery.IsDeleted      = false;
                List <ORM_RES_BLD_Apartment> appartmentList = ORM_RES_BLD_Apartment.Query.Search(Connection, Transaction, appartmentQuery);

                if (appartmentList.Count > Parameter.AppartmentCount)
                {
                    int counts = appartmentList.Count - Parameter.AppartmentCount;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Apartment deleteAppartment = appartmentList[i];
                        deleteAppartment.Remove(Connection, Transaction);
                    }
                }
                else if (appartmentList.Count < Parameter.AppartmentCount)
                {
                    int counts = Parameter.AppartmentCount - appartmentList.Count;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Apartment newAppartment = new ORM_RES_BLD_Apartment();
                        newAppartment.Building_RefID = Parameter.RES_BLD_BuildingID;
                        newAppartment.Tenant_RefID   = securityTicket.TenantID;
                        newAppartment.Save(Connection, Transaction);
                    }
                }

                ORM_RES_BLD_OutdoorFacility.Query outdoorfacilitiesQuery = new ORM_RES_BLD_OutdoorFacility.Query();
                outdoorfacilitiesQuery.Building_RefID = Parameter.RES_BLD_BuildingID;
                outdoorfacilitiesQuery.Tenant_RefID   = securityTicket.TenantID;
                outdoorfacilitiesQuery.IsDeleted      = false;
                List <ORM_RES_BLD_OutdoorFacility> outdoorfacilitiesList = ORM_RES_BLD_OutdoorFacility.Query.Search(Connection, Transaction, outdoorfacilitiesQuery);

                if (outdoorfacilitiesList.Count > Parameter.outdoorfacilitiesCount)
                {
                    int counts = outdoorfacilitiesList.Count - Parameter.outdoorfacilitiesCount;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_OutdoorFacility deleteOutdoor = outdoorfacilitiesList[i];
                        deleteOutdoor.Remove(Connection, Transaction);
                    }
                }
                else if (outdoorfacilitiesList.Count < Parameter.outdoorfacilitiesCount)
                {
                    int counts = Parameter.outdoorfacilitiesCount - outdoorfacilitiesList.Count;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_OutdoorFacility newOutdoorFacility = new ORM_RES_BLD_OutdoorFacility();
                        newOutdoorFacility.Building_RefID = building.RES_BLD_BuildingID;
                        newOutdoorFacility.Tenant_RefID   = securityTicket.TenantID;
                        newOutdoorFacility.Save(Connection, Transaction);
                    }
                }


                ORM_RES_BLD_Staircase.Query staircaseQuery = new ORM_RES_BLD_Staircase.Query();
                staircaseQuery.Building_RefID = Parameter.RES_BLD_BuildingID;
                staircaseQuery.Tenant_RefID   = securityTicket.TenantID;
                staircaseQuery.IsDeleted      = false;
                List <ORM_RES_BLD_Staircase> staircaseList = ORM_RES_BLD_Staircase.Query.Search(Connection, Transaction, staircaseQuery);

                if (staircaseList.Count > Parameter.staircasesCount)
                {
                    int counts = staircaseList.Count - Parameter.staircasesCount;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Staircase deleteStaircase = staircaseList[i];
                        deleteStaircase.Remove(Connection, Transaction);
                    }
                }
                else if (staircaseList.Count < Parameter.staircasesCount)
                {
                    int counts = Parameter.staircasesCount - staircaseList.Count;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Staircase newStaircase = new ORM_RES_BLD_Staircase();
                        newStaircase.Building_RefID = building.RES_BLD_BuildingID;
                        newStaircase.Tenant_RefID   = securityTicket.TenantID;
                        newStaircase.Save(Connection, Transaction);
                    }
                }

                ORM_RES_BLD_Facade.Query facadesQuery = new ORM_RES_BLD_Facade.Query();
                facadesQuery.Building_RefID = Parameter.RES_BLD_BuildingID;
                facadesQuery.Tenant_RefID   = securityTicket.TenantID;
                facadesQuery.IsDeleted      = false;
                List <ORM_RES_BLD_Facade> facadesList = ORM_RES_BLD_Facade.Query.Search(Connection, Transaction, facadesQuery);

                if (facadesList.Count > Parameter.facadesCount)
                {
                    int counts = facadesList.Count - Parameter.facadesCount;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Facade deleteFacade = facadesList[i];
                        deleteFacade.Remove(Connection, Transaction);
                    }
                }
                else if (facadesList.Count < Parameter.facadesCount)
                {
                    int counts = Parameter.facadesCount - facadesList.Count;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Facade newFacade = new ORM_RES_BLD_Facade();
                        newFacade.Building_RefID = building.RES_BLD_BuildingID;
                        newFacade.Tenant_RefID   = securityTicket.TenantID;
                        newFacade.Save(Connection, Transaction);
                    }
                }

                ORM_RES_BLD_Roof.Query roofQuery = new ORM_RES_BLD_Roof.Query();
                roofQuery.Building_RefID = Parameter.RES_BLD_BuildingID;
                roofQuery.Tenant_RefID   = securityTicket.TenantID;
                roofQuery.IsDeleted      = false;
                List <ORM_RES_BLD_Roof> roofList = ORM_RES_BLD_Roof.Query.Search(Connection, Transaction, roofQuery);

                if (roofList.Count > Parameter.roofCount)
                {
                    int counts = roofList.Count - Parameter.roofCount;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Roof deleteRoof = roofList[i];
                        deleteRoof.Remove(Connection, Transaction);
                    }
                }
                else if (roofList.Count < Parameter.roofCount)
                {
                    int counts = Parameter.roofCount - roofList.Count;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Roof newRoof = new ORM_RES_BLD_Roof();
                        newRoof.Building_RefID = building.RES_BLD_BuildingID;
                        newRoof.Tenant_RefID   = securityTicket.TenantID;
                        newRoof.Save(Connection, Transaction);
                    }
                }

                ORM_RES_BLD_Attic.Query atticsQuery = new ORM_RES_BLD_Attic.Query();
                atticsQuery.Building_RefID = Parameter.RES_BLD_BuildingID;
                atticsQuery.Tenant_RefID   = securityTicket.TenantID;
                atticsQuery.IsDeleted      = false;
                List <ORM_RES_BLD_Attic> atticsList = ORM_RES_BLD_Attic.Query.Search(Connection, Transaction, atticsQuery);

                if (atticsList.Count > Parameter.atticsCount)
                {
                    int counts = atticsList.Count - Parameter.atticsCount;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Attic deleteAttic = atticsList[i];
                        deleteAttic.Remove(Connection, Transaction);
                    }
                }
                else if (atticsList.Count < Parameter.atticsCount)
                {
                    int counts = Parameter.atticsCount - atticsList.Count;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Attic newAttic = new ORM_RES_BLD_Attic();
                        newAttic.Building_RefID = building.RES_BLD_BuildingID;
                        newAttic.Tenant_RefID   = securityTicket.TenantID;
                        newAttic.Save(Connection, Transaction);
                    }
                }

                ORM_RES_BLD_Basement.Query basementQuery = new ORM_RES_BLD_Basement.Query();
                basementQuery.Building_RefID = Parameter.RES_BLD_BuildingID;
                basementQuery.Tenant_RefID   = securityTicket.TenantID;
                basementQuery.IsDeleted      = false;
                List <ORM_RES_BLD_Basement> basementList = ORM_RES_BLD_Basement.Query.Search(Connection, Transaction, basementQuery);

                if (basementList.Count > Parameter.basementsCount)
                {
                    int counts = basementList.Count - Parameter.basementsCount;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Basement deleteBasement = basementList[i];
                        deleteBasement.Remove(Connection, Transaction);
                    }
                }
                else if (basementList.Count < Parameter.basementsCount)
                {
                    int counts = Parameter.basementsCount - basementList.Count;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_Basement newBasement = new ORM_RES_BLD_Basement();
                        newBasement.Building_RefID = building.RES_BLD_BuildingID;
                        newBasement.Tenant_RefID   = securityTicket.TenantID;
                        newBasement.Save(Connection, Transaction);
                    }
                }

                ORM_RES_BLD_HVACR.Query hvacrQuery = new ORM_RES_BLD_HVACR.Query();
                hvacrQuery.Building_RefID = Parameter.RES_BLD_BuildingID;
                hvacrQuery.Tenant_RefID   = securityTicket.TenantID;
                hvacrQuery.IsDeleted      = false;
                List <ORM_RES_BLD_HVACR> hvacrList = ORM_RES_BLD_HVACR.Query.Search(Connection, Transaction, hvacrQuery);

                if (hvacrList.Count > Parameter.hvarcsCount)
                {
                    int counts = hvacrList.Count - Parameter.hvarcsCount;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_HVACR deleteHvacr = hvacrList[i];
                        deleteHvacr.Remove(Connection, Transaction);
                    }
                }
                else if (hvacrList.Count < Parameter.hvarcsCount)
                {
                    int counts = Parameter.hvarcsCount - hvacrList.Count;
                    for (int i = 0; i < counts; i++)
                    {
                        ORM_RES_BLD_HVACR newHvacr = new ORM_RES_BLD_HVACR();
                        newHvacr.Building_RefID = building.RES_BLD_BuildingID;
                        newHvacr.Tenant_RefID   = securityTicket.TenantID;
                        newHvacr.Save(Connection, Transaction);
                    }
                }
            }

            returnValue.Result = building.RES_BLD_BuildingID;

            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5BD_GBFRG_1005_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5BD_GBFRG_1005 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5BD_GBFRG_1005_Array();
            //Put your code here

            List <L5BD_GBFRG_1005>     returnList = new List <L5BD_GBFRG_1005>();
            ORM_RES_DUD_Revision.Query rvQuery    = new ORM_RES_DUD_Revision.Query();
            rvQuery.IsDeleted           = false;
            rvQuery.Tenant_RefID        = securityTicket.TenantID;
            rvQuery.RevisionGroup_RefID = Parameter.RevisionGroupID;
            List <ORM_RES_DUD_Revision> revisions = ORM_RES_DUD_Revision.Query.Search(Connection, Transaction, rvQuery);


            foreach (var revision in revisions)
            {
                ORM_RES_BLD_Building bdQuery = new ORM_RES_BLD_Building();
                L5BD_GBFRG_1005      item    = new L5BD_GBFRG_1005();

                ORM_RES_BLD_Building building = new ORM_RES_BLD_Building();
                building.Load(Connection, Transaction, revision.RES_BLD_Building_RefID);

                ORM_RES_BLD_Apartment.Query apQuery = new ORM_RES_BLD_Apartment.Query();
                apQuery.Tenant_RefID   = securityTicket.TenantID;
                apQuery.IsDeleted      = false;
                apQuery.Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_Apartment> apList = ORM_RES_BLD_Apartment.Query.Search(Connection, Transaction, apQuery);

                List <L5BD_GBFRG_1005_Apartment> apResult = new List <L5BD_GBFRG_1005_Apartment>();
                foreach (var part in apList)
                {
                    L5BD_GBFRG_1005_Apartment itemPart = new L5BD_GBFRG_1005_Apartment();
                    itemPart.ApartmentSize_Unit_RefID    = part.ApartmentSize_Unit_RefID;
                    itemPart.ApartmentSize_Value         = part.ApartmentSize_Value;
                    itemPart.IsAppartment_ForRent        = part.IsDeleted;
                    itemPart.RES_BLD_ApartmentID         = part.RES_BLD_ApartmentID;
                    itemPart.Appartment_FlooringType     = part.TypeOfFlooring_RefID;
                    itemPart.Appartment_HeatingType      = part.TypeOfHeating_RefID;
                    itemPart.Appartment_WallCoveringType = part.TypeOfWallCovering_RefID;

                    ORM_RES_STR_Apartment strApartment = ORM_RES_STR_Apartment.Query.Search(Connection, Transaction, new ORM_RES_STR_Apartment.Query()
                    {
                        RES_BLD_Apartment_RefID = part.RES_BLD_ApartmentID,
                        Tenant_RefID            = securityTicket.TenantID,
                        IsDeleted = false
                    }).FirstOrDefault();
                    if (strApartment != null)
                    {
                        itemPart.ApartmentsDocumentHeader_RefID = strApartment.DocumentHeader_RefID;

                        Guid[] documentHeaders = ORM_RES_STR_Apartment_PropertyAssessment.Query.Search(Connection, Transaction, new ORM_RES_STR_Apartment_PropertyAssessment.Query()
                        {
                            STR_Apartment_RefID = strApartment.RES_STR_ApartmentID,
                            IsDeleted           = false,
                            Tenant_RefID        = securityTicket.TenantID
                        }).Select(i => i.DocumentHeader_RefID).ToArray();

                        if (documentHeaders != null)
                        {
                            itemPart.ApartmentsPropertyDocumentHeaders = documentHeaders;
                        }
                    }

                    apResult.Add(itemPart);
                }
                item.Apartments = apResult.ToArray();


                ORM_RES_BLD_Attic.Query atQuery = new ORM_RES_BLD_Attic.Query();
                atQuery.Tenant_RefID   = securityTicket.TenantID;
                atQuery.IsDeleted      = false;
                atQuery.Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_Attic> atList = ORM_RES_BLD_Attic.Query.Search(Connection, Transaction, atQuery);

                List <L5BD_GBFRG_1005_Attic> atResult = new List <L5BD_GBFRG_1005_Attic>();
                foreach (var part in atList)
                {
                    L5BD_GBFRG_1005_Attic itemPart = new L5BD_GBFRG_1005_Attic();
                    itemPart.RES_BLD_AtticID = part.RES_BLD_AtticID;

                    ORM_RES_STR_Attic strAttic = ORM_RES_STR_Attic.Query.Search(Connection, Transaction, new ORM_RES_STR_Attic.Query()
                    {
                        RES_BLD_Attic_RefID = part.RES_BLD_AtticID,
                        Tenant_RefID        = securityTicket.TenantID,
                        IsDeleted           = false
                    }).FirstOrDefault();
                    if (strAttic != null)
                    {
                        itemPart.AtticsDocumentHeader_RefID = strAttic.DocumentHeader_RefID;

                        Guid[] documentHeaders = ORM_RES_STR_Attic_PropertyAssessment.Query.Search(Connection, Transaction, new ORM_RES_STR_Attic_PropertyAssessment.Query()
                        {
                            STR_Attic_RefID = strAttic.RES_STR_AtticID,
                            IsDeleted       = false,
                            Tenant_RefID    = securityTicket.TenantID
                        }).Select(i => i.DocumentHeader_RefID).ToArray();

                        if (documentHeaders != null)
                        {
                            itemPart.AtticsPropertyDocumentHeaders = documentHeaders;
                        }
                    }

                    atResult.Add(itemPart);
                }
                item.Attics = atResult.ToArray();

                ORM_RES_BLD_Basement.Query baQuery = new ORM_RES_BLD_Basement.Query();
                baQuery.Tenant_RefID   = securityTicket.TenantID;
                baQuery.IsDeleted      = false;
                baQuery.Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_Basement> baList = ORM_RES_BLD_Basement.Query.Search(Connection, Transaction, baQuery);

                List <L5BD_GBFRG_1005_Basement> baResult = new List <L5BD_GBFRG_1005_Basement>();
                foreach (var part in baList)
                {
                    L5BD_GBFRG_1005_Basement itemPart = new L5BD_GBFRG_1005_Basement();
                    itemPart.Basement_FloorType = part.TypeOfFloor_RefID;
                    itemPart.RES_BLD_BasementID = part.RES_BLD_BasementID;

                    ORM_RES_STR_Basement strBasement = ORM_RES_STR_Basement.Query.Search(Connection, Transaction, new ORM_RES_STR_Basement.Query()
                    {
                        RES_BLD_Basement_RefID = part.RES_BLD_BasementID,
                        Tenant_RefID           = securityTicket.TenantID,
                        IsDeleted = false
                    }).FirstOrDefault();
                    if (strBasement != null)
                    {
                        itemPart.BasementsDocumentHeader_RefID = strBasement.DocumentHeader_RefID;

                        Guid[] documentHeaders = ORM_RES_STR_Basement_PropertyAssessment.Query.Search(Connection, Transaction, new ORM_RES_STR_Basement_PropertyAssessment.Query()
                        {
                            STR_Basement_RefID = strBasement.RES_STR_BasementID,
                            IsDeleted          = false,
                            Tenant_RefID       = securityTicket.TenantID
                        }).Select(i => i.DocumentHeader_RefID).ToArray();

                        if (documentHeaders != null)
                        {
                            itemPart.BasementsPropertyDocumentHeaders = documentHeaders;
                        }
                    }

                    baResult.Add(itemPart);
                }
                item.Basements = baResult.ToArray();

                ORM_RES_BLD_Facade.Query faQuery = new ORM_RES_BLD_Facade.Query();
                faQuery.Tenant_RefID   = securityTicket.TenantID;
                faQuery.IsDeleted      = false;
                faQuery.Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_Facade> faList = ORM_RES_BLD_Facade.Query.Search(Connection, Transaction, faQuery);

                List <L5BD_GBFRG_1005_Facade> faResult = new List <L5BD_GBFRG_1005_Facade>();
                foreach (var part in faList)
                {
                    L5BD_GBFRG_1005_Facade itemPart = new L5BD_GBFRG_1005_Facade();
                    itemPart.RES_BLD_FacadeID = part.RES_BLD_FacadeID;

                    ORM_RES_STR_Facade strFacade = ORM_RES_STR_Facade.Query.Search(Connection, Transaction, new ORM_RES_STR_Facade.Query()
                    {
                        RES_BLD_Facade_RefID = part.RES_BLD_FacadeID,
                        Tenant_RefID         = securityTicket.TenantID,
                        IsDeleted            = false
                    }).FirstOrDefault();
                    if (strFacade != null)
                    {
                        itemPart.FacadesDocumentHeader_RefID = strFacade.DocumentHeader_RefID;

                        Guid[] documentHeaders = ORM_RES_STR_Facade_PropertyAssessment.Query.Search(Connection, Transaction, new ORM_RES_STR_Facade_PropertyAssessment.Query()
                        {
                            STR_Facade_RefID = strFacade.RES_STR_FacadeID,
                            IsDeleted        = false,
                            Tenant_RefID     = securityTicket.TenantID
                        }).Select(i => i.DocumentHeader_RefID).ToArray();

                        if (documentHeaders != null)
                        {
                            itemPart.FacadesPropertyDocumentHeaders = documentHeaders;
                        }
                    }

                    faResult.Add(itemPart);
                }
                item.Facades = faResult.ToArray();

                ORM_RES_BLD_HVACR.Query hvQuery = new ORM_RES_BLD_HVACR.Query();
                hvQuery.Tenant_RefID   = securityTicket.TenantID;
                hvQuery.IsDeleted      = false;
                hvQuery.Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_HVACR> hvList = ORM_RES_BLD_HVACR.Query.Search(Connection, Transaction, hvQuery);

                List <L5BD_GBFRG_1005_HVACR> hvResult = new List <L5BD_GBFRG_1005_HVACR>();
                foreach (var part in hvList)
                {
                    L5BD_GBFRG_1005_HVACR itemPart = new L5BD_GBFRG_1005_HVACR();
                    itemPart.RES_BLD_HVACRID = part.RES_BLD_HVACRID;

                    ORM_RES_STR_HVACR strHVACR = ORM_RES_STR_HVACR.Query.Search(Connection, Transaction, new ORM_RES_STR_HVACR.Query()
                    {
                        RES_BLD_HVACR_RefID = part.RES_BLD_HVACRID,
                        Tenant_RefID        = securityTicket.TenantID,
                        IsDeleted           = false
                    }).FirstOrDefault();
                    if (strHVACR != null)
                    {
                        itemPart.HVACRsDocumentHeader_RefID = strHVACR.DocumentHeader_RefID;

                        Guid[] documentHeaders = ORM_RES_STR_HVACR_PropertyAssessment.Query.Search(Connection, Transaction, new ORM_RES_STR_HVACR_PropertyAssessment.Query()
                        {
                            STR_HVACR_RefID = strHVACR.RES_STR_HVACRID,
                            IsDeleted       = false,
                            Tenant_RefID    = securityTicket.TenantID
                        }).Select(i => i.DocumentHeader_RefID).ToArray();

                        if (documentHeaders != null)
                        {
                            itemPart.HVACRsPropertyDocumentHeaders = documentHeaders;
                        }
                    }

                    hvResult.Add(itemPart);
                }
                item.HVACRs = hvResult.ToArray();

                ORM_RES_BLD_OutdoorFacility.Query ofQuery = new ORM_RES_BLD_OutdoorFacility.Query();
                ofQuery.Tenant_RefID   = securityTicket.TenantID;
                ofQuery.IsDeleted      = false;
                ofQuery.Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_OutdoorFacility> ofList = ORM_RES_BLD_OutdoorFacility.Query.Search(Connection, Transaction, ofQuery);

                List <L5BD_GBFRG_1005_OutdoorFacility> ofResult = new List <L5BD_GBFRG_1005_OutdoorFacility>();
                foreach (var part in ofList)
                {
                    L5BD_GBFRG_1005_OutdoorFacility itemPart = new L5BD_GBFRG_1005_OutdoorFacility();
                    itemPart.OutdoorFacility_AccessRoadType = part.TypeOfAccessRoad_RefID;
                    itemPart.OutdoorFacility_FenceType      = part.TypeOfFence_RefID;
                    itemPart.RES_BLD_OutdoorFacilityID      = part.RES_BLD_OutdoorFacilityID;

                    ORM_RES_STR_OutdoorFacility strOutdoorFacility = ORM_RES_STR_OutdoorFacility.Query.Search(Connection, Transaction, new ORM_RES_STR_OutdoorFacility.Query()
                    {
                        RES_BLD_OutdoorFacility_RefID = part.RES_BLD_OutdoorFacilityID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).FirstOrDefault();
                    if (strOutdoorFacility != null)
                    {
                        itemPart.OutdoorFacilitiesDocumentHeader_RefID = strOutdoorFacility.DocumentHeader_RefID;

                        Guid[] documentHeaders = ORM_RES_STR_OutdoorFacility_PropertyAssessment.Query.Search(Connection, Transaction, new ORM_RES_STR_OutdoorFacility_PropertyAssessment.Query()
                        {
                            STR_OutdoorFacility_RefID = strOutdoorFacility.RES_STR_OutdoorFacilityID,
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID
                        }).Select(i => i.DocumentHeader_RefID).ToArray();

                        if (documentHeaders != null)
                        {
                            itemPart.OutdoorFacilitiesPropertyDocumentHeaders = documentHeaders;
                        }
                    }

                    ofResult.Add(itemPart);
                }
                item.OutdoorFacilities = ofResult.ToArray();

                ORM_RES_BLD_Roof.Query roQuery = new ORM_RES_BLD_Roof.Query();
                roQuery.Tenant_RefID   = securityTicket.TenantID;
                roQuery.IsDeleted      = false;
                roQuery.Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_Roof> roList = ORM_RES_BLD_Roof.Query.Search(Connection, Transaction, roQuery);

                List <L5BD_GBFRG_1005_Roof> roResult = new List <L5BD_GBFRG_1005_Roof>();
                foreach (var part in roList)
                {
                    L5BD_GBFRG_1005_Roof itemPart = new L5BD_GBFRG_1005_Roof();

                    itemPart.RES_BLD_Roof_Type_RefID = ORM_RES_BLD_Roof_2_RoofType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Roof_2_RoofType.Query()
                    {
                        Tenant_RefID       = securityTicket.TenantID,
                        IsDeleted          = false,
                        RES_BLD_Roof_RefID = part.RES_BLD_RoofID
                    }).Select(r => r.RES_BLD_Roof_Type_RefID).FirstOrDefault();

                    itemPart.RES_BLD_RoofID = part.RES_BLD_RoofID;

                    ORM_RES_STR_Roof strRoof = ORM_RES_STR_Roof.Query.Search(Connection, Transaction, new ORM_RES_STR_Roof.Query()
                    {
                        RES_BLD_Roof_RefID = part.RES_BLD_RoofID,
                        Tenant_RefID       = securityTicket.TenantID,
                        IsDeleted          = false
                    }).FirstOrDefault();
                    if (strRoof != null)
                    {
                        itemPart.RoofsDocumentHeader_RefID = strRoof.DocumentHeader_RefID;

                        Guid[] documentHeaders = ORM_RES_STR_Roof_PropertyAssessment.Query.Search(Connection, Transaction, new ORM_RES_STR_Roof_PropertyAssessment.Query()
                        {
                            STR_Roof_RefID = strRoof.RES_STR_RoofID,
                            IsDeleted      = false,
                            Tenant_RefID   = securityTicket.TenantID
                        }).Select(i => i.DocumentHeader_RefID).ToArray();

                        if (documentHeaders != null)
                        {
                            itemPart.RoofsPropertyDocumentHeaders = documentHeaders;
                        }
                    }

                    roResult.Add(itemPart);
                }
                item.Roofs = roResult.ToArray();

                ORM_RES_BLD_Staircase.Query stQuery = new ORM_RES_BLD_Staircase.Query();
                stQuery.Tenant_RefID   = securityTicket.TenantID;
                stQuery.IsDeleted      = false;
                stQuery.Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_Staircase> stList = ORM_RES_BLD_Staircase.Query.Search(Connection, Transaction, stQuery);

                List <L5BD_GBFRG_1005_Staircase> stResult = new List <L5BD_GBFRG_1005_Staircase>();
                foreach (var part in stList)
                {
                    L5BD_GBFRG_1005_Staircase itemPart = new L5BD_GBFRG_1005_Staircase();
                    itemPart.RES_BLD_StaircaseID = part.RES_BLD_StaircaseID;

                    ORM_RES_STR_Staircase strStaircase = ORM_RES_STR_Staircase.Query.Search(Connection, Transaction, new ORM_RES_STR_Staircase.Query()
                    {
                        RES_BLD_Staircase_RefID = part.RES_BLD_StaircaseID,
                        Tenant_RefID            = securityTicket.TenantID,
                        IsDeleted = false
                    }).FirstOrDefault();
                    if (strStaircase != null)
                    {
                        itemPart.StaircasesDocumentHeader_RefID = strStaircase.DocumentHeader_RefID;

                        Guid[] documentHeaders = ORM_RES_STR_Staircase_PropertyAssessment.Query.Search(Connection, Transaction, new ORM_RES_STR_Staircase_PropertyAssessment.Query()
                        {
                            STR_Staircase_RefID = strStaircase.RES_STR_StaircaseID,
                            IsDeleted           = false,
                            Tenant_RefID        = securityTicket.TenantID
                        }).Select(i => i.DocumentHeader_RefID).ToArray();

                        if (documentHeaders != null)
                        {
                            itemPart.StaircasesPropertyDocumentHeaders = documentHeaders;
                        }
                    }
                    stResult.Add(itemPart);
                }
                item.Staircases = stResult.ToArray();


                item.Building_BalconyPortionPercent        = building.Building_BalconyPortionPercent;
                item.Building_DocumentationStructure_RefID = building.Building_DocumentationStructure_RefID;
                item.Building_ElevatorCoveragePercent      = building.Building_ElevatorCoveragePercent;
                item.Building_Name = building.Building_Name;
                item.Building_NumberOfAppartments         = building.Building_NumberOfAppartments;
                item.Building_NumberOfFloors              = building.Building_NumberOfFloors;
                item.Building_NumberOfOccupiedAppartments = building.Building_NumberOfOccupiedAppartments;
                item.Building_NumberOfOffices             = building.Building_NumberOfOffices;
                item.Building_NumberOfOtherUnits          = building.Building_NumberOfOtherUnits;
                item.Building_NumberOfProductionUnits     = building.Building_NumberOfProductionUnits;
                item.Building_NumberOfRetailUnits         = building.Building_NumberOfRetailUnits;
                item.IsContaminationSuspected             = building.IsContaminationSuspected;
                item.RES_BLD_BuildingID = building.RES_BLD_BuildingID;

                ORM_RES_BLD_Building_2_GarbageContainerType.Query gctQuery = new ORM_RES_BLD_Building_2_GarbageContainerType.Query();
                gctQuery.Tenant_RefID           = securityTicket.TenantID;
                gctQuery.IsDeleted              = false;
                gctQuery.RES_BLD_Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_Building_2_GarbageContainerType> garbageContainerType = ORM_RES_BLD_Building_2_GarbageContainerType.Query.Search(Connection, Transaction, gctQuery);


                ORM_RES_BLD_Building_2_BuildingType.Query b2tQuery = new ORM_RES_BLD_Building_2_BuildingType.Query();
                b2tQuery.Tenant_RefID           = securityTicket.TenantID;
                b2tQuery.IsDeleted              = false;
                b2tQuery.RES_BLD_Building_RefID = building.RES_BLD_BuildingID;
                List <ORM_RES_BLD_Building_2_BuildingType> buildingType = ORM_RES_BLD_Building_2_BuildingType.Query.Search(Connection, Transaction, b2tQuery);


                ORM_RES_BLD_Building_Type.Query btQuery = new ORM_RES_BLD_Building_Type.Query();
                btQuery.Tenant_RefID            = securityTicket.TenantID;
                btQuery.IsDeleted               = false;
                btQuery.RES_BLD_Building_TypeID = buildingType.FirstOrDefault().RES_BLD_Building_Type_RefID;
                List <ORM_RES_BLD_Building_Type> btList = ORM_RES_BLD_Building_Type.Query.Search(Connection, Transaction, btQuery);

                ORM_RES_BLD_GarbageContainerType.Query gcQuery = new ORM_RES_BLD_GarbageContainerType.Query();
                gcQuery.Tenant_RefID = securityTicket.TenantID;
                gcQuery.IsDeleted    = false;
                gcQuery.RES_BLD_GarbageContainerTypeID = garbageContainerType.FirstOrDefault().RES_BLD_GarbageContainerType_RefID;
                List <ORM_RES_BLD_GarbageContainerType> gcList = ORM_RES_BLD_GarbageContainerType.Query.Search(Connection, Transaction, gcQuery);

                if (btList.Count != 0)
                {
                    item.Building_Type = btList.FirstOrDefault().BuildingType_Name;
                }
                if (gcList.Count != 0)
                {
                    item.Building_GarbageContainerType = gcList.FirstOrDefault().GarbageContainerType_Name;
                }

                item.QuestionnaireVersion_RefID = revision.QuestionnaireVersion_RefID;
                item.RES_DUD_RevisionID         = revision.RES_DUD_RevisionID;

                returnList.Add(item);
            }

            returnValue.Result = returnList.ToArray();
            return(returnValue);

            #endregion UserCode
        }