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

            ORM_RES_DUD_RevisionGroup.Query revisionGroup = new ORM_RES_DUD_RevisionGroup.Query();
            revisionGroup.RES_DUD_Revision_GroupID = Parameter.DueDiligenceID;
            revisionGroup.Tenant_RefID             = securityTicket.TenantID;
            revisionGroup.IsDeleted = false;
            returnValue.Result      = new L5RP_GRPFDD_1148();
            returnValue.Result.RES_RealestatePropertyID = ORM_RES_DUD_RevisionGroup.Query.Search(Connection, Transaction, revisionGroup).FirstOrDefault().RealestateProperty_RefID;

            return(returnValue);

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

            ORM_RES_DUD_RevisionGroup.Query dueDiligenceQuery = new ORM_RES_DUD_RevisionGroup.Query();
            dueDiligenceQuery.Tenant_RefID             = securityTicket.TenantID;
            dueDiligenceQuery.RES_DUD_Revision_GroupID = Parameter.DueDiligenceID;
            ORM_RES_DUD_RevisionGroup.Query.SoftDelete(Connection, Transaction, dueDiligenceQuery);

            ORM_RES_DUD_Revision.Query revisionQuery = new ORM_RES_DUD_Revision.Query();
            revisionQuery.Tenant_RefID        = securityTicket.TenantID;
            revisionQuery.RevisionGroup_RefID = Parameter.DueDiligenceID;
            ORM_RES_DUD_Revision.Query.SoftDelete(Connection, Transaction, revisionQuery);

            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5DD_GRGFRP_1403_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5DD_GRGFRP_1403 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5DD_GRGFRP_1403_Array();
            var retVal      = new List <L5DD_GRGFRP_1403>();
            L5DD_GRGFRP_1403 revisionGroupItem;

            //Put your code here
            #region Realestate
            ORM_RES_RealestateProperty realestateProperty = new ORM_RES_RealestateProperty();
            if (Parameter.RealestatePropertyID != Guid.Empty)
            {
                var realestatePropertyResult = realestateProperty.Load(Connection, Transaction, Parameter.RealestatePropertyID);
                if (realestatePropertyResult.Status != FR_Status.Success || realestateProperty.RES_RealestatePropertyID == Guid.Empty)
                {
                    return(null);
                }
            }
            #endregion

            #region Address
            ORM_CMN_Address address = new ORM_CMN_Address();

            ORM_CMN_LOC_Location location = new ORM_CMN_LOC_Location();
            var locationResult            = location.Load(Connection, Transaction, realestateProperty.RealestateProperty_Location_RefID);
            if (locationResult.Status == FR_Status.Success && location.CMN_LOC_LocationID != Guid.Empty)
            {
                var addressResult = address.Load(Connection, Transaction, location.Address_RefID);
                if (locationResult.Status != FR_Status.Success || location.CMN_LOC_LocationID == Guid.Empty)
                {
                    address = null;
                }
            }
            #endregion

            #region Revision groups for realestrate
            ORM_RES_DUD_RevisionGroup.Query revisionGroupQuery = new ORM_RES_DUD_RevisionGroup.Query();
            revisionGroupQuery.Tenant_RefID             = securityTicket.TenantID;
            revisionGroupQuery.IsDeleted                = false;
            revisionGroupQuery.RealestateProperty_RefID = realestateProperty.RES_RealestatePropertyID;
            List <ORM_RES_DUD_RevisionGroup> revisionGroupList = ORM_RES_DUD_RevisionGroup.Query.Search(Connection, Transaction, revisionGroupQuery);
            #endregion

            #region Buildings for realestate
            ORM_RES_BLD_Building_RevisionHeader.Query revisionHeaderQuery = new ORM_RES_BLD_Building_RevisionHeader.Query();
            revisionHeaderQuery.Tenant_RefID             = securityTicket.TenantID;
            revisionHeaderQuery.IsDeleted                = false;
            revisionHeaderQuery.RealestateProperty_RefID = realestateProperty.RES_RealestatePropertyID;
            ORM_RES_BLD_Building_RevisionHeader revisionHeader = ORM_RES_BLD_Building_RevisionHeader.Query.Search(Connection, Transaction, revisionHeaderQuery).FirstOrDefault();

            List <ORM_RES_BLD_Building> buildings = new List <ORM_RES_BLD_Building>();
            List <ORM_RES_DUD_Revision> revisions = new List <ORM_RES_DUD_Revision>();
            List <ORM_RES_BLD_Building_2_BuildingType>         buildingTypes = new List <ORM_RES_BLD_Building_2_BuildingType>();
            List <ORM_RES_BLD_Building_2_GarbageContainerType> buildingGarbageContainerType = new List <ORM_RES_BLD_Building_2_GarbageContainerType>();
            if (revisionHeader != null)
            {
                ORM_RES_BLD_Building.Query buildingQuery = new ORM_RES_BLD_Building.Query();
                buildingQuery.Tenant_RefID = securityTicket.TenantID;
                buildingQuery.IsDeleted    = false;
                buildingQuery.BuildingRevisionHeader_RefID = revisionHeader.RES_BLD_Building_RevisionHeaderID;
                buildings = ORM_RES_BLD_Building.Query.Search(Connection, Transaction, buildingQuery);

                if (buildings == null)
                {
                    buildings = new List <ORM_RES_BLD_Building>();
                }

                #region revisions and building types for every building
                foreach (var buildingItem in buildings)
                {
                    ORM_RES_DUD_Revision.Query revisionQuery = new ORM_RES_DUD_Revision.Query();
                    revisionQuery.Tenant_RefID           = securityTicket.TenantID;
                    revisionQuery.IsDeleted              = false;
                    revisionQuery.RES_BLD_Building_RefID = buildingItem.RES_BLD_BuildingID;
                    revisions.AddRange(ORM_RES_DUD_Revision.Query.Search(Connection, Transaction, revisionQuery));

                    ORM_RES_BLD_Building_2_BuildingType.Query buildingTypeQuery = new ORM_RES_BLD_Building_2_BuildingType.Query();
                    buildingTypeQuery.Tenant_RefID           = securityTicket.TenantID;
                    buildingTypeQuery.IsDeleted              = false;
                    buildingTypeQuery.RES_BLD_Building_RefID = buildingItem.RES_BLD_BuildingID;
                    buildingTypes.AddRange(ORM_RES_BLD_Building_2_BuildingType.Query.Search(Connection, Transaction, buildingTypeQuery));

                    ORM_RES_BLD_Building_2_GarbageContainerType.Query buildingGarbageContainerTypeQuery = new ORM_RES_BLD_Building_2_GarbageContainerType.Query();
                    buildingGarbageContainerTypeQuery.Tenant_RefID           = securityTicket.TenantID;
                    buildingGarbageContainerTypeQuery.IsDeleted              = false;
                    buildingGarbageContainerTypeQuery.RES_BLD_Building_RefID = buildingItem.RES_BLD_BuildingID;
                    buildingGarbageContainerType.AddRange(ORM_RES_BLD_Building_2_GarbageContainerType.Query.Search(Connection, Transaction, buildingGarbageContainerTypeQuery));
                }
                #endregion
            }
            #endregion

            #region Revision groups
            List <L5DD_GRGFRP_1403_Buildings> buildingsResult;
            L5DD_GRGFRP_1403_Buildings        buildingResult;
            foreach (var revisionGroup in revisionGroupList)
            {
                revisionGroupItem = new L5DD_GRGFRP_1403();
                revisionGroupItem.RES_DUD_Revision_GroupID = revisionGroup.RES_DUD_Revision_GroupID;
                revisionGroupItem.RevisionGroup_Name       = revisionGroup.RevisionGroup_Name;
                revisionGroupItem.RevisionGroup_SubmittedBy_Account_RefID = revisionGroup.RevisionGroup_SubmittedBy_Account_RefID;
                revisionGroupItem.Creation_Timestamp       = revisionGroup.Creation_Timestamp;
                revisionGroupItem.Tenant_RefID             = revisionGroup.Tenant_RefID;
                revisionGroupItem.IsDeleted                = revisionGroup.IsDeleted;
                revisionGroupItem.RealestateProperty_RefID = revisionGroup.RealestateProperty_RefID;
                revisionGroupItem.RevisionGroup_Comment    = revisionGroup.RevisionGroup_Comment;

                #region Person info
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();

                ORM_CMN_PER_PersonInfo_2_Account.Query personInfoAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                personInfoAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                personInfoAccountQuery.IsDeleted         = false;
                personInfoAccountQuery.USR_Account_RefID = revisionGroup.RevisionGroup_SubmittedBy_Account_RefID;
                ORM_CMN_PER_PersonInfo_2_Account account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personInfoAccountQuery).FirstOrDefault();

                if (account != null)
                {
                    var personInfoResult = personInfo.Load(Connection, Transaction, account.CMN_PER_PersonInfo_RefID);
                    if (personInfoResult.Status == FR_Status.Success && personInfo.CMN_PER_PersonInfoID != Guid.Empty)
                    {
                        revisionGroupItem.FirstName = personInfo.FirstName;
                        revisionGroupItem.LastName  = personInfo.LastName;
                    }
                }
                #endregion

                #region set address info
                if (address != null)
                {
                    revisionGroupItem.Country_Name    = address.Country_Name;
                    revisionGroupItem.City_Region     = address.City_Region;
                    revisionGroupItem.City_PostalCode = address.City_PostalCode;
                    revisionGroupItem.City_Name       = address.City_Name;
                    revisionGroupItem.Street_Name     = address.Street_Name;
                    revisionGroupItem.Street_Number   = address.Street_Number;
                }
                #endregion

                #region set building info
                buildingsResult = new List <L5DD_GRGFRP_1403_Buildings>();

                // get revisions for revision group
                var revisionsForRetVal = revisions.Where(i => i.RevisionGroup_RefID == revisionGroup.RES_DUD_Revision_GroupID).ToList();
                ORM_RES_DUD_Revision revisionForBuildingID;

                // get buildings for list of revision
                List <ORM_RES_BLD_Building> buildingForRetVal = new List <ORM_RES_BLD_Building>();
                buildingForRetVal.AddRange(buildings.Where(i => revisionsForRetVal.Any(j => j.RES_BLD_Building_RefID == i.RES_BLD_BuildingID)).ToList());

                foreach (var buildingForRetValItem in buildingForRetVal)
                {
                    revisionForBuildingID = revisionsForRetVal.FirstOrDefault(i => i.RES_BLD_Building_RefID == buildingForRetValItem.RES_BLD_BuildingID);

                    buildingResult = new L5DD_GRGFRP_1403_Buildings();
                    buildingResult.Building_Name              = buildingForRetValItem.Building_Name;
                    buildingResult.RES_BLD_BuildingID         = buildingForRetValItem.RES_BLD_BuildingID;
                    buildingResult.RES_DUD_RevisionID         = revisionForBuildingID.RES_DUD_RevisionID;
                    buildingResult.QuestionnaireVersion_RefID = revisionForBuildingID.QuestionnaireVersion_RefID;

                    buildingResult.RES_BLD_Building_Type_RefID        = buildingTypes.FirstOrDefault(i => i.RES_BLD_Building_RefID == buildingForRetValItem.RES_BLD_BuildingID).RES_BLD_Building_Type_RefID;
                    buildingResult.RES_BLD_GarbageContainerType_RefID = buildingGarbageContainerType.FirstOrDefault(i => i.RES_BLD_Building_RefID == buildingForRetValItem.RES_BLD_BuildingID).RES_BLD_GarbageContainerType_RefID;

                    buildingsResult.Add(buildingResult);
                }
                #endregion

                revisionGroupItem.Buildings = buildingsResult.ToArray();
                retVal.Add(revisionGroupItem);
            }
            #endregion

            returnValue.Result = retVal.ToArray();

            return(returnValue);

            #endregion UserCode
        }