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

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                else
                {
                    address.IsDeleted = true;
                    address.Save(Connection, Transaction);

                    ORM_CMN_PER_PersonInfo_2_Address.Query query = new ORM_CMN_PER_PersonInfo_2_Address.Query();
                    query.CMN_Address_RefID = address.CMN_AddressID;
                    query.Tenant_RefID      = securityTicket.TenantID;
                    query.IsDeleted         = false;

                    var queryRes = ORM_CMN_PER_PersonInfo_2_Address.Query.SoftDelete(Connection, Transaction, query);
                }
            }

            return(returnValue);

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

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                else
                {
                    ORM_CMN_PER_PersonInfo_2_Address.Query query = new ORM_CMN_PER_PersonInfo_2_Address.Query();
                    query.CMN_Address_RefID = address.CMN_AddressID;
                    query.Tenant_RefID      = securityTicket.TenantID;
                    query.IsDeleted         = false;
                    var queryRes = ORM_CMN_PER_PersonInfo_2_Address.Query.Search(Connection, Transaction, query);
                    if (queryRes.Count == 1)
                    {
                        queryRes[0].IsPrimary = true;
                        queryRes[0].Save(Connection, Transaction);

                        ORM_CMN_PER_PersonInfo_2_Address.Query queryOther = new ORM_CMN_PER_PersonInfo_2_Address.Query();
                        queryOther.CMN_PER_PersonInfo_RefID = queryRes[0].CMN_PER_PersonInfo_RefID;
                        queryOther.Tenant_RefID             = securityTicket.TenantID;
                        queryOther.IsDeleted = false;
                        var queryOtherRes = ORM_CMN_PER_PersonInfo_2_Address.Query.Search(Connection, Transaction, queryOther);
                        if (queryOtherRes.Count > 0)
                        {
                            foreach (ORM_CMN_PER_PersonInfo_2_Address item in queryOtherRes)
                            {
                                if (item.AssignmentID != queryRes[0].AssignmentID)
                                {
                                    item.IsPrimary = false;
                                    item.Save(Connection, Transaction);
                                }
                            }
                        }
                    }
                    else
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                }
            }

            return(returnValue);

            #endregion UserCode
        }
예제 #3
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2AD_SA_1755 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            var returnValue = new FR_Guid();

            var item = new ORM_CMN_Address();

            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                item.Load(Connection, Transaction, Parameter.CMN_AddressID);
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_AddressID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.CMN_AddressID == Guid.Empty)
            {
                item.Tenant_RefID = securityTicket.TenantID;
            }

            item.Street_Name   = Parameter.Street_Name;
            item.Street_Number = Parameter.Street_Number;
            item.City_AdministrativeDistrict = Parameter.City_AdministrativeDistrict;
            item.City_Region     = Parameter.City_Region;
            item.City_Name       = Parameter.City_Name;
            item.City_PostalCode = Parameter.City_PostalCode;
            item.Province_Name   = Parameter.Province_Name;
            item.Country_Name    = Parameter.Country_Name;
            item.CareOf          = Parameter.CareOf;
            item.Country_ISOCode = Parameter.Country_ISOCode;
            item.Province_EconomicRegion_RefID = Parameter.Province_EconomicRegion_RefID;

            return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_AddressID));
        }
예제 #4
0
        protected static FR_L5LI_GCLIFRP_0936 Execute(DbConnection Connection, DbTransaction Transaction, P_L5LI_GCLIFRP_0936 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5LI_GCLIFRP_0936();

            returnValue.Result = new L5LI_GCLIFRP_0936();

            ORM_RES_RealestateProperty orm_realestate = new ORM_RES_RealestateProperty();
            orm_realestate.Load(Connection, Transaction, Parameter.RealestatePropertyID);

            ORM_CMN_LOC_Location orm_location = new ORM_CMN_LOC_Location();
            orm_location.Load(Connection, Transaction, orm_realestate.RealestateProperty_Location_RefID);
            returnValue.Result.CMN_LOC_LocationID = orm_location.CMN_LOC_LocationID;

            ORM_CMN_Address orm_address = new ORM_CMN_Address();
            orm_address.Load(Connection, Transaction, orm_location.Address_RefID);

            L5LI_GCLIFRP_0936_Address address = new L5LI_GCLIFRP_0936_Address();
            address.CMN_AddressID               = orm_address.CMN_AddressID;
            address.Street_Name                 = orm_address.Street_Name;
            address.Street_Number               = orm_address.Street_Number;
            address.City_PostalCode             = orm_address.City_PostalCode;
            address.City_Name                   = orm_address.City_Name;
            address.City_Region                 = orm_address.City_Region;
            address.City_AdministrativeDistrict = orm_address.City_AdministrativeDistrict;
            address.Province_Name               = orm_address.Province_Name;

            returnValue.Result.Address = address;


            ORM_CMN_LOC_Region orm_region = new ORM_CMN_LOC_Region();
            orm_region.Load(Connection, Transaction, orm_location.Region_RefID);

            L5LI_GCLIFRP_0936_Region region = new L5LI_GCLIFRP_0936_Region();
            region.CMN_LOC_RegionID = orm_region.CMN_LOC_RegionID;
            region.Country_RefID    = orm_region.Country_RefID;

            returnValue.Result.Region = region;


            ORM_RES_LOC_LocationInformation.Query locationInfoQuery = new ORM_RES_LOC_LocationInformation.Query();
            locationInfoQuery.CMN_LOC_Location_RefID = orm_location.CMN_LOC_LocationID;
            locationInfoQuery.Tenant_RefID           = securityTicket.TenantID;
            locationInfoQuery.IsDeleted = false;
            ORM_RES_LOC_LocationInformation locationInfoFromQuery = ORM_RES_LOC_LocationInformation.Query.Search(Connection, Transaction, locationInfoQuery).FirstOrDefault();

            L5LI_GCLIFRP_0936_LocationInformation locationInfo = new L5LI_GCLIFRP_0936_LocationInformation();
            locationInfo.RES_LOC_LocationInformationID = locationInfoFromQuery.RES_LOC_LocationInformationID;
            locationInfo.MapImage      = locationInfoFromQuery.LocationInformation_MapImage_DocID;
            locationInfo.SateliteImage = locationInfoFromQuery.LocationInformation_SatelliteImage_DocID;
            locationInfo.AddressImage  = locationInfoFromQuery.LocationInformation_AddressImage_DocID;

            returnValue.Result.LocationInformation = locationInfo;

            ORM_RES_LOC_RegionInformation.Query regionInfoQuery = new ORM_RES_LOC_RegionInformation.Query();
            regionInfoQuery.CMN_LOC_Region_RefID = orm_region.CMN_LOC_RegionID;
            regionInfoQuery.Tenant_RefID         = securityTicket.TenantID;
            regionInfoQuery.IsDeleted            = false;
            List <ORM_RES_LOC_RegionInformation> regionInfos = ORM_RES_LOC_RegionInformation.Query.Search(Connection, Transaction, regionInfoQuery);

            L5LI_GCLIFRP_0936_RegionInformation regionInfo = new L5LI_GCLIFRP_0936_RegionInformation();
            regionInfo.RegionInformation_RegionArea_in_sqkm                    = regionInfos[0].RegionInformation_RegionArea_in_sqkm;
            regionInfo.RegionInformation_TotalPopulation                       = regionInfos[0].RegionInformation_TotalPopulation;
            regionInfo.RegionInformation_Population_per_sqkm                   = regionInfos[0].RegionInformation_Population_per_sqkm;
            regionInfo.RegionInformation_RegionUnemploymentRatePercent         = regionInfos[0].RegionInformation_RegionUnemploymentRatePercent;
            regionInfo.RegionInformation_NumberOfHouseholds_Current            = regionInfos[0].RegionInformation_NumberOfHouseholds_Current;
            regionInfo.RegionInformation_NumberOfHouseholds_Forecast           = regionInfos[0].RegionInformation_NumberOfHouseholds_Forecast;
            regionInfo.RegionInformation_PurchasingPowerAmount_Current_RefID   = regionInfos[0].RegionInformation_PurchasingPowerAmount_Current_RefID;
            regionInfo.RegionInformation_PurchasingPowerAmount_Forecast_RefID  = regionInfos[0].RegionInformation_PurchasingPowerAmount_Forecast_RefID;
            regionInfo.RegionInformation_ResidentialRent_MinPrice_RefID        = regionInfos[0].RegionInformation_ResidentialRent_MinPrice_RefID;
            regionInfo.RegionInformation_ResidentialRent_AveragePrice_RefID    = regionInfos[0].RegionInformation_ResidentialRent_AveragePrice_RefID;
            regionInfo.RegionInformation_ResidentialRent_MaxPrice_RefID        = regionInfos[0].RegionInformation_ResidentialRent_MaxPrice_RefID;
            regionInfo.RegionInformation_NonResidentialRent_MinPrice_RefID     = regionInfos[0].RegionInformation_NonResidentialRent_MinPrice_RefID;
            regionInfo.RegionInformation_NonResidentialRent_AveragePrice_RefID = regionInfos[0].RegionInformation_NonResidentialRent_AveragePrice_RefID;
            regionInfo.RegionInformation_NonResidentialRent_MaxPrice_RefID     = regionInfos[0].RegionInformation_NonResidentialRent_MaxPrice_RefID;

            returnValue.Result.RegionInformation = regionInfo;

            P_L2PR_GPVFP_0932 priceParam = new P_L2PR_GPVFP_0932();
            priceParam.PriceID = regionInfos[0].RegionInformation_NonResidentialRent_AveragePrice_RefID;
            returnValue.Result.RegionInformation_NonResidentialRent_AveragePrice_Amount = cls_Get_PriceValue_For_PriceID.Invoke(Connection, Transaction, priceParam, securityTicket).Result.PriceValue_Amount;

            priceParam.PriceID = regionInfos[0].RegionInformation_NonResidentialRent_MaxPrice_RefID;
            returnValue.Result.RegionInformation_NonResidentialRent_MaxPrice_Amount = cls_Get_PriceValue_For_PriceID.Invoke(Connection, Transaction, priceParam, securityTicket).Result.PriceValue_Amount;

            priceParam.PriceID = regionInfos[0].RegionInformation_NonResidentialRent_MinPrice_RefID;
            returnValue.Result.RegionInformation_NonResidentialRent_MinPrice_Amount = cls_Get_PriceValue_For_PriceID.Invoke(Connection, Transaction, priceParam, securityTicket).Result.PriceValue_Amount;

            priceParam.PriceID = regionInfos[0].RegionInformation_PurchasingPowerAmount_Current_RefID;
            returnValue.Result.RegionInformation_PurchasingPowerAmount_Current_Amount = cls_Get_PriceValue_For_PriceID.Invoke(Connection, Transaction, priceParam, securityTicket).Result.PriceValue_Amount;

            priceParam.PriceID = regionInfos[0].RegionInformation_PurchasingPowerAmount_Forecast_RefID;
            returnValue.Result.RegionInformation_PurchasingPowerAmount_Forecast_Amount = cls_Get_PriceValue_For_PriceID.Invoke(Connection, Transaction, priceParam, securityTicket).Result.PriceValue_Amount;

            priceParam.PriceID = regionInfos[0].RegionInformation_ResidentialRent_AveragePrice_RefID;
            returnValue.Result.RegionInformation_ResidentialRent_AveragePrice_Amount = cls_Get_PriceValue_For_PriceID.Invoke(Connection, Transaction, priceParam, securityTicket).Result.PriceValue_Amount;

            priceParam.PriceID = regionInfos[0].RegionInformation_ResidentialRent_MaxPrice_RefID;
            returnValue.Result.RegionInformation_ResidentialRent_MaxPrice_Amount = cls_Get_PriceValue_For_PriceID.Invoke(Connection, Transaction, priceParam, securityTicket).Result.PriceValue_Amount;

            priceParam.PriceID = regionInfos[0].RegionInformation_ResidentialRent_MinPrice_RefID;
            returnValue.Result.RegionInformation_ResidentialRent_MinPrice_Amount = cls_Get_PriceValue_For_PriceID.Invoke(Connection, Transaction, priceParam, securityTicket).Result.PriceValue_Amount;


            //result.Means_of_Transportation
            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query locationInfo_2_mot_Query = new ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query();
            locationInfo_2_mot_Query.RES_LOC_LocationInformation_RefID = locationInfoFromQuery.RES_LOC_LocationInformationID;
            locationInfo_2_mot_Query.Tenant_RefID = securityTicket.TenantID;
            locationInfo_2_mot_Query.IsDeleted    = false;
            List <ORM_RES_LOC_LocationInformation_2_MeansOfTransportation> locationInfo_2_mots = ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query.Search(Connection, Transaction, locationInfo_2_mot_Query);

            List <L5LI_GCLIFRP_0936_MeansOfTransportation> MeansOfTransportation_List = new List <L5LI_GCLIFRP_0936_MeansOfTransportation>();
            L5LI_GCLIFRP_0936_MeansOfTransportation        MeansOfTransportation;
            if (locationInfo_2_mots.Count > 0)
            {
                ORM_RES_LOC_MeansOfTransportation.Query motQuery;
                foreach (var locationInfi_2_mot in locationInfo_2_mots)
                {
                    motQuery = new ORM_RES_LOC_MeansOfTransportation.Query();
                    motQuery.RES_LOC_MeansOfTransportationID = locationInfi_2_mot.RES_LOC_MeansOfTransportation_RefID;
                    motQuery.Tenant_RefID = securityTicket.TenantID;
                    motQuery.IsDeleted    = false;
                    List <ORM_RES_LOC_MeansOfTransportation> mots = ORM_RES_LOC_MeansOfTransportation.Query.Search(Connection, Transaction, motQuery);

                    MeansOfTransportation = new L5LI_GCLIFRP_0936_MeansOfTransportation();
                    MeansOfTransportation.MeansOfTransportation_ID   = mots[0].RES_LOC_MeansOfTransportationID;
                    MeansOfTransportation.MeansOfTransportation_Name = mots[0].Transportation_Name;

                    MeansOfTransportation_List.Add(MeansOfTransportation);
                }
            }
            returnValue.Result.MeansOfTransportation = MeansOfTransportation_List.ToArray();


            //result.Emmissions
            ORM_RES_LOC_LocationInformation_2_Emmission.Query emmissions_Query = new ORM_RES_LOC_LocationInformation_2_Emmission.Query();
            emmissions_Query.RES_LOC_LocationInformation_RefID = locationInfoFromQuery.RES_LOC_LocationInformationID;
            emmissions_Query.Tenant_RefID = securityTicket.TenantID;
            emmissions_Query.IsDeleted    = false;
            List <ORM_RES_LOC_LocationInformation_2_Emmission> emmissions = ORM_RES_LOC_LocationInformation_2_Emmission.Query.Search(Connection, Transaction, emmissions_Query);

            List <L5LI_GCLIFRP_0936_Emmissions> Emmissions_List = new List <L5LI_GCLIFRP_0936_Emmissions>();
            L5LI_GCLIFRP_0936_Emmissions        Emmission;
            if (emmissions.Count > 0)
            {
                ORM_RES_LOC_Emmission.Query emmissionQuery;
                foreach (var emmission in emmissions)
                {
                    emmissionQuery = new ORM_RES_LOC_Emmission.Query();
                    emmissionQuery.RES_LOC_EmmissionID = emmission.RES_LOC_Emmission_RefID;
                    emmissionQuery.Tenant_RefID        = securityTicket.TenantID;
                    emmissionQuery.IsDeleted           = false;
                    List <ORM_RES_LOC_Emmission> orm_emmissions = ORM_RES_LOC_Emmission.Query.Search(Connection, Transaction, emmissionQuery);

                    Emmission = new L5LI_GCLIFRP_0936_Emmissions();
                    Emmission.Emmissions_ID   = orm_emmissions[0].RES_LOC_EmmissionID;
                    Emmission.Emmissions_Name = orm_emmissions[0].Emmission_Name;

                    Emmissions_List.Add(Emmission);
                }
            }
            returnValue.Result.Emmissions = Emmissions_List.ToArray();


            //result.SurroundingInfrastructures
            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query SurroundingInfrastructures_Query = new ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query();
            SurroundingInfrastructures_Query.RES_LOC_LocationInformation_RefID = locationInfoFromQuery.RES_LOC_LocationInformationID;
            SurroundingInfrastructures_Query.Tenant_RefID = securityTicket.TenantID;
            SurroundingInfrastructures_Query.IsDeleted    = false;
            List <ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure> SurroundingInfrastructures = ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query.Search(Connection, Transaction, SurroundingInfrastructures_Query);

            List <L5LI_GCLIFRP_0936_SurroundingInfrastructures> SurroundingInfrastructures_List = new List <L5LI_GCLIFRP_0936_SurroundingInfrastructures>();
            L5LI_GCLIFRP_0936_SurroundingInfrastructures        SurroundingInfrastructure;
            if (SurroundingInfrastructures.Count > 0)
            {
                ORM_RES_LOC_SurroundingInfrastructure.Query SurroundingInfrastructure_Query;
                foreach (var infrastructure in SurroundingInfrastructures)
                {
                    SurroundingInfrastructure_Query = new ORM_RES_LOC_SurroundingInfrastructure.Query();
                    SurroundingInfrastructure_Query.RES_LOC_SurroundingInfrastructureID = infrastructure.RES_LOC_SurroundingInfrastructure_RefID;
                    SurroundingInfrastructure_Query.Tenant_RefID = securityTicket.TenantID;
                    SurroundingInfrastructure_Query.IsDeleted    = false;
                    List <ORM_RES_LOC_SurroundingInfrastructure> orm_SurroundingInfrastructure = ORM_RES_LOC_SurroundingInfrastructure.Query.Search(Connection, Transaction, SurroundingInfrastructure_Query);

                    SurroundingInfrastructure = new L5LI_GCLIFRP_0936_SurroundingInfrastructures();
                    SurroundingInfrastructure.SurroundingInfrastructures_ID   = orm_SurroundingInfrastructure[0].RES_LOC_SurroundingInfrastructureID;
                    SurroundingInfrastructure.SurroundingInfrastructures_Name = orm_SurroundingInfrastructure[0].SurroundingInfrastructure_Name;

                    SurroundingInfrastructures_List.Add(SurroundingInfrastructure);
                }
            }
            returnValue.Result.SurroundingInfrastructures = SurroundingInfrastructures_List.ToArray();


            //result.Neighborhood
            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query neighborhoodQuality_Query = new ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query();
            neighborhoodQuality_Query.RES_LOC_LocationInformation_RefID = locationInfoFromQuery.RES_LOC_LocationInformationID;
            neighborhoodQuality_Query.Tenant_RefID = securityTicket.TenantID;
            neighborhoodQuality_Query.IsDeleted    = false;
            List <ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality> neighborhoodQualities = ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query.Search(Connection, Transaction, neighborhoodQuality_Query);

            List <L5LI_GCLIFRP_0936_NeighborhoodQualities> NeighborhoodQualities_List = new List <L5LI_GCLIFRP_0936_NeighborhoodQualities>();
            L5LI_GCLIFRP_0936_NeighborhoodQualities        NeighborhoodQuality;
            if (neighborhoodQualities.Count > 0)
            {
                ORM_RES_LOC_NeighborhoodQuality.Query NeighborhoodQuality_Query;
                foreach (var quality in neighborhoodQualities)
                {
                    NeighborhoodQuality_Query = new ORM_RES_LOC_NeighborhoodQuality.Query();
                    NeighborhoodQuality_Query.RES_LOC_NeighborhoodQualityID = quality.RES_LOC_NeighborhoodQuality_RefID;
                    NeighborhoodQuality_Query.Tenant_RefID = securityTicket.TenantID;
                    NeighborhoodQuality_Query.IsDeleted    = false;
                    List <ORM_RES_LOC_NeighborhoodQuality> orm_neighborhoodQualities = ORM_RES_LOC_NeighborhoodQuality.Query.Search(Connection, Transaction, NeighborhoodQuality_Query);

                    NeighborhoodQuality = new L5LI_GCLIFRP_0936_NeighborhoodQualities();
                    NeighborhoodQuality.NeighborhoodQualities_ID   = orm_neighborhoodQualities[0].RES_LOC_NeighborhoodQualityID;
                    NeighborhoodQuality.NeighborhoodQualities_Name = orm_neighborhoodQualities[0].NeighborhoodQuality_Name;

                    NeighborhoodQualities_List.Add(NeighborhoodQuality);
                }
            }
            returnValue.Result.NeighborhoodQualities = NeighborhoodQualities_List.ToArray();


            //result.ParkingSituation
            ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query parkingSituation_Query = new ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query();
            parkingSituation_Query.RES_LOC_LocationInfo_RefID = locationInfoFromQuery.RES_LOC_LocationInformationID;
            parkingSituation_Query.Tenant_RefID = securityTicket.TenantID;
            parkingSituation_Query.IsDeleted    = false;
            List <ORM_RES_LOC_LocationInfo_2_ParkingSituation> parkingSituations = ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query.Search(Connection, Transaction, parkingSituation_Query);

            List <L5LI_GCLIFRP_0936_ParkingSituations> ParkingSituations_List = new List <L5LI_GCLIFRP_0936_ParkingSituations>();
            L5LI_GCLIFRP_0936_ParkingSituations        ParkingSituation;
            if (parkingSituations.Count > 0)
            {
                ORM_RES_LOC_ParkingSituation.Query ParkingSituation_Query;
                foreach (var situtaion in parkingSituations)
                {
                    ParkingSituation_Query = new ORM_RES_LOC_ParkingSituation.Query();
                    ParkingSituation_Query.RES_LOC_ParkingSituationID = situtaion.RES_LOC_ParkingSituation_RefID;
                    ParkingSituation_Query.Tenant_RefID = securityTicket.TenantID;
                    ParkingSituation_Query.IsDeleted    = false;
                    List <ORM_RES_LOC_ParkingSituation> orm_parkingSituations = ORM_RES_LOC_ParkingSituation.Query.Search(Connection, Transaction, ParkingSituation_Query);

                    ParkingSituation = new L5LI_GCLIFRP_0936_ParkingSituations();
                    ParkingSituation.ParkingSituations_ID   = orm_parkingSituations[0].RES_LOC_ParkingSituationID;
                    ParkingSituation.ParkingSituations_Name = orm_parkingSituations[0].ParkingSituation_Name;

                    ParkingSituations_List.Add(ParkingSituation);
                }
            }
            returnValue.Result.ParkingSituations = ParkingSituations_List.ToArray();


            //result.ResidentialVacancies
            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query residentialVacancy_Query = new ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query();
            residentialVacancy_Query.RES_LOC_LocationInfo_RefID = locationInfoFromQuery.RES_LOC_LocationInformationID;
            residentialVacancy_Query.Tenant_RefID = securityTicket.TenantID;
            residentialVacancy_Query.IsDeleted    = false;
            List <ORM_RES_LOC_LocationInfo_2_ResidentialVacancy> residentalVacancies = ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query.Search(Connection, Transaction, residentialVacancy_Query);

            List <L5LI_GCLIFRP_0936_ResidentialVacancies> ResidentialVacancies_List = new List <L5LI_GCLIFRP_0936_ResidentialVacancies>();
            L5LI_GCLIFRP_0936_ResidentialVacancies        ResidentialVacancy;
            if (residentalVacancies.Count > 0)
            {
                ORM_RES_LOC_ResidentialVacancy.Query ResidentialVacancy_Query;
                foreach (var vacancy in residentalVacancies)
                {
                    ResidentialVacancy_Query = new ORM_RES_LOC_ResidentialVacancy.Query();
                    ResidentialVacancy_Query.RES_LOC_ResidentialVacancyID = vacancy.RES_LOC_ResidentialVacancy_RefID;
                    ResidentialVacancy_Query.Tenant_RefID = securityTicket.TenantID;
                    ResidentialVacancy_Query.IsDeleted    = false;
                    List <ORM_RES_LOC_ResidentialVacancy> orm_residentalVacancies = ORM_RES_LOC_ResidentialVacancy.Query.Search(Connection, Transaction, ResidentialVacancy_Query);

                    ResidentialVacancy = new L5LI_GCLIFRP_0936_ResidentialVacancies();
                    ResidentialVacancy.ResidentialVacancies_ID   = orm_residentalVacancies[0].RES_LOC_ResidentialVacancyID;
                    ResidentialVacancy.ResidentialVacancies_Name = orm_residentalVacancies[0].ResidentialVacancy_Name;

                    ResidentialVacancies_List.Add(ResidentialVacancy);
                }
            }
            returnValue.Result.ResidentialVacancies = ResidentialVacancies_List.ToArray();


            //return.CommercialVacancies
            ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query commercialVacancies_Query = new ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query();
            commercialVacancies_Query.RES_LOC_LocationInfo_RefID = locationInfoFromQuery.RES_LOC_LocationInformationID;
            commercialVacancies_Query.Tenant_RefID = securityTicket.TenantID;
            commercialVacancies_Query.IsDeleted    = false;
            List <ORM_RES_LOC_LocationInfo_2_CommercialVacancy> commaericalVacancies = ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query.Search(Connection, Transaction, commercialVacancies_Query);

            List <L5LI_GCLIFRP_0936_CommercialVacancies> CommercialVacancies_List = new List <L5LI_GCLIFRP_0936_CommercialVacancies>();
            L5LI_GCLIFRP_0936_CommercialVacancies        CommercialVacancy;
            if (commaericalVacancies.Count > 0)
            {
                ORM_RES_LOC_CommercialVacancy.Query CommercialVacancies_Query;
                foreach (var vacancy in commaericalVacancies)
                {
                    CommercialVacancies_Query = new ORM_RES_LOC_CommercialVacancy.Query();
                    CommercialVacancies_Query.RES_LOC_CommercialVacancyID = vacancy.RES_LOC_CommercialVacancy_RefID;
                    CommercialVacancies_Query.Tenant_RefID = securityTicket.TenantID;
                    CommercialVacancies_Query.IsDeleted    = false;
                    List <ORM_RES_LOC_CommercialVacancy> orm_commercialVacancies = ORM_RES_LOC_CommercialVacancy.Query.Search(Connection, Transaction, CommercialVacancies_Query);

                    CommercialVacancy = new L5LI_GCLIFRP_0936_CommercialVacancies();
                    CommercialVacancy.CommercialVacancies_ID   = orm_commercialVacancies[0].RES_LOC_CommercialVacancyID;
                    CommercialVacancy.CommercialVacancies_Name = orm_commercialVacancies[0].CommercialVacancy_Name;

                    CommercialVacancies_List.Add(CommercialVacancy);
                }
            }
            returnValue.Result.CommercialVacancies = CommercialVacancies_List.ToArray();


            //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
        }
        protected static FR_L5EM_GEFT_0959_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5EM_GEFT_0959_Array();
            List <L5EM_GEFT_0959>          employeeResultList = new List <L5EM_GEFT_0959>();
            ORM_CMN_BPT_EMP_Employee.Query employeeQuery      = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);

            foreach (var employeeItem in employeeList)
            {
                L5EM_GEFT_0959           result   = new L5EM_GEFT_0959();
                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, employeeItem.CMN_BPT_EMP_EmployeeID);
                result.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
                result.Staff_Number           = employee.Staff_Number;
                result.StandardFunction       = employee.StandardFunction;

                ORM_USR_Account.Query accountQuery = new ORM_USR_Account.Query();
                accountQuery.BusinessParticipant_RefID = employee.BusinessParticipant_RefID;
                accountQuery.Tenant_RefID = securityTicket.TenantID;
                accountQuery.IsDeleted    = false;
                ORM_USR_Account account = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery).FirstOrDefault();
                if (account != null)
                {
                    result.USR_AccountID = account.USR_AccountID;
                }

                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                result.CMN_BPT_BusinessParticipantID = businessParticipant.CMN_BPT_BusinessParticipantID;
                result.DisplayName = businessParticipant.DisplayName;

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                result.CMN_PER_PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                result.FirstName            = personInfo.FirstName;
                result.LastName             = personInfo.LastName;
                result.PrimaryEmail         = personInfo.PrimaryEmail;
                result.Title = personInfo.Title;
                result.ProfileImage_Document_RefID = personInfo.ProfileImage_Document_RefID;
                result.BirthDate = personInfo.BirthDate;

                ORM_CMN_BPT_EMP_EmploymentRelationship.Query workingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship.Query();
                workingContractQuery.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                workingContractQuery.IsDeleted      = false;
                workingContractQuery.Tenant_RefID   = securityTicket.TenantID;
                ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = ORM_CMN_BPT_EMP_EmploymentRelationship.Query.Search(Connection, Transaction, workingContractQuery).FirstOrDefault();

                result.CMN_BPT_EMP_EmploymentRelationshipID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                result.Work_StartDate = employmentRelationship.Work_StartDate;
                result.Work_EndDate   = employmentRelationship.Work_EndDate;

                //Address
                if (personInfo.Address_RefID != Guid.Empty)
                {
                    ORM_CMN_Address address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    result.CMN_AddressID = address.CMN_AddressID;
                    result.Street_Name   = address.Street_Name;
                    result.Street_Number = address.Street_Number;
                    result.City_AdministrativeDistrict = address.City_AdministrativeDistrict;
                    result.City_Region     = address.City_Region;
                    result.City_Name       = address.City_Name;
                    result.City_PostalCode = address.City_PostalCode;
                    result.Province_Name   = address.Province_Name;
                    result.Country_Name    = address.Country_Name;
                    result.Country_ISOCode = address.Country_ISOCode;
                }

                //Contacts
                ORM_CMN_PER_CommunicationContact.Query comunicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query();
                comunicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                comunicationContactQuery.Tenant_RefID     = securityTicket.TenantID;
                comunicationContactQuery.IsDeleted        = false;
                List <ORM_CMN_PER_CommunicationContact> comunicationContacts       = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, comunicationContactQuery);
                List <L5EM_GEFT_0959_Contacts>          resultComunicationContacts = new List <L5EM_GEFT_0959_Contacts>();
                foreach (var comunicationContact in comunicationContacts)
                {
                    ORM_CMN_PER_CommunicationContact_Type contactType = new ORM_CMN_PER_CommunicationContact_Type();
                    contactType.Load(Connection, Transaction, comunicationContact.CMN_PER_CommunicationContactID);
                    L5EM_GEFT_0959_Contacts resultComunicationContact = new L5EM_GEFT_0959_Contacts();
                    resultComunicationContact.CMN_PER_CommunicationContact_TypeID = contactType.CMN_PER_CommunicationContact_TypeID;
                    resultComunicationContact.CMN_PER_CommunicationContactID      = comunicationContact.CMN_PER_CommunicationContactID;
                    resultComunicationContact.Content = comunicationContact.Content;
                    resultComunicationContact.Type    = contactType.Type;
                    resultComunicationContacts.Add(resultComunicationContact);
                }
                result.Contacts = resultComunicationContacts.ToArray();


                //Employee workplace history
                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GEFT_0959_EmployeeWorkplaceHistory>      employeeWorkplaceAssignments     = new List <L5EM_GEFT_0959_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GEFT_0959_EmployeeWorkplaceHistory item = new L5EM_GEFT_0959_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();


                //Contracts

                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query contractTermQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                contractTermQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                contractTermQuery.IsDeleted    = false;
                contractTermQuery.Tenant_RefID = securityTicket.TenantID;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> contracts = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, contractTermQuery);
                List <L5EM_GEFT_0959_WorkingContracts> resultContracts = new List <L5EM_GEFT_0959_WorkingContracts>();
                foreach (var contractToRelationship in contracts)
                {
                    L5EM_GEFT_0959_WorkingContracts resultContract = new L5EM_GEFT_0959_WorkingContracts();

                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    workingContract.Load(Connection, Transaction, contractToRelationship.WorkingContract_RefID);
                    if (!workingContract.IsDeleted)
                    {
                        resultContract.CMN_BPT_EMP_WorkingContractID = workingContract.CMN_BPT_EMP_WorkingContractID;
                        resultContract.EmploymentRelationshipToWorkingContractAssignmentID = contractToRelationship.AssignmentID;
                        resultContract.IsWorkingContract_Active     = contractToRelationship.IsContract_Active;
                        resultContract.Contract_StartDate           = workingContract.Contract_StartDate;
                        resultContract.Contract_EndDate             = workingContract.Contract_EndDate;
                        resultContract.IsContractEndDateDefined     = workingContract.IsContractEndDateDefined;
                        resultContract.IsWorkTimeCalculated_InDays  = workingContract.IsWorkTimeCalculated_InDays;
                        resultContract.IsWorkTimeCalculated_InHours = workingContract.IsWorkTimeCalculated_InHours;
                        resultContract.R_WorkTime_DaysPerWeek       = workingContract.R_WorkTime_DaysPerWeek;
                        resultContract.R_WorkTime_HoursPerWeek      = workingContract.R_WorkTime_HoursPerWeek;

                        //Office hours
                        ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query workingContractTermToWorkingDayQuery = new ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query();
                        workingContractTermToWorkingDayQuery.CMN_BPT_EMP_WorkingContract_RefID = workingContract.CMN_BPT_EMP_WorkingContractID;
                        workingContractTermToWorkingDayQuery.Tenant_RefID = securityTicket.TenantID;
                        workingContractTermToWorkingDayQuery.IsDeleted    = false;
                        List <ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay> workingDayAssigments    = ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query.Search(Connection, Transaction, workingContractTermToWorkingDayQuery);
                        List <L5EM_GEFT_0959_WeeklyOfficeHours>             resultWeeklyOfficeHours = new List <L5EM_GEFT_0959_WeeklyOfficeHours>();
                        foreach (var workingDayAssigment in workingDayAssigments)
                        {
                            ORM_CMN_CAL_WeeklyOfficeHours_Interval interval = new ORM_CMN_CAL_WeeklyOfficeHours_Interval();
                            interval.Load(Connection, Transaction, workingDayAssigment.CMN_CAL_WeeklyOfficeHours_Interval_RefID);

                            L5EM_GEFT_0959_WeeklyOfficeHours resultOfficeHour = new L5EM_GEFT_0959_WeeklyOfficeHours();
                            resultOfficeHour.CMN_CAL_WeeklyOfficeHours_IntervalID = interval.CMN_CAL_WeeklyOfficeHours_IntervalID;
                            resultOfficeHour.IsFriday           = interval.IsFriday;
                            resultOfficeHour.IsMonday           = interval.IsMonday;
                            resultOfficeHour.IsSaturday         = interval.IsSaturday;
                            resultOfficeHour.IsSunday           = interval.IsSunday;
                            resultOfficeHour.IsThursday         = interval.IsThursday;
                            resultOfficeHour.IsTuesday          = interval.IsTuesday;
                            resultOfficeHour.IsWednesday        = interval.IsWednesday;
                            resultOfficeHour.IsWholeDay         = interval.IsWholeDay;
                            resultOfficeHour.TimeFrom_InMinutes = interval.TimeFrom_InMinutes;
                            resultOfficeHour.TimeTo_InMinutes   = interval.TimeTo_InMinutes;
                            resultWeeklyOfficeHours.Add(resultOfficeHour);
                        }
                        resultContract.WeeklyOfficeHours = resultWeeklyOfficeHours.ToArray();


                        //Allowed absence reasons
                        ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query AllowedAbsenceReasonQuery = new ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query();
                        AllowedAbsenceReasonQuery.WorkingContract_RefID = resultContract.CMN_BPT_EMP_WorkingContractID;
                        AllowedAbsenceReasonQuery.Tenant_RefID          = securityTicket.TenantID;
                        AllowedAbsenceReasonQuery.IsDeleted             = false;
                        List <ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason> allowedAbsenceReasons       = ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query.Search(Connection, Transaction, AllowedAbsenceReasonQuery);
                        List <L5EM_GEFT_0959_WorkingContractToLeaveRequest>         resultAllowedAbsenceReasons = new List <L5EM_GEFT_0959_WorkingContractToLeaveRequest>();
                        foreach (var allowedAbsenceReason in allowedAbsenceReasons)
                        {
                            ORM_CMN_BPT_STA_AbsenceReason absenceReason = new ORM_CMN_BPT_STA_AbsenceReason();
                            absenceReason.Load(Connection, Transaction, allowedAbsenceReason.STA_AbsenceReason_RefID);

                            L5EM_GEFT_0959_WorkingContractToLeaveRequest resultReasonresultReason = new L5EM_GEFT_0959_WorkingContractToLeaveRequest();
                            resultReasonresultReason.CMN_BPT_EMP_Employee_WorkingContract_AllowedAbsenceReasonID = allowedAbsenceReason.CMN_BPT_EMP_WorkingContract_AllowedAbsenceReasonID;
                            resultReasonresultReason.STA_AbsenceReason_RefID          = absenceReason.CMN_BPT_STA_AbsenceReasonID;
                            resultReasonresultReason.IsAbsenceCalculated_InDays       = allowedAbsenceReason.IsAbsenceCalculated_InDays;
                            resultReasonresultReason.IsAbsenceCalculated_InHours      = allowedAbsenceReason.IsAbsenceCalculated_InHours;
                            resultReasonresultReason.ContractAllowedAbsence_per_Month = allowedAbsenceReason.ContractAllowedAbsence_per_Month;
                            resultAllowedAbsenceReasons.Add(resultReasonresultReason);
                        }
                        resultContract.WorkingContractToLeaveRequest = resultAllowedAbsenceReasons.ToArray();

                        resultContracts.Add(resultContract);
                    }
                }
                result.WorkingContracts = resultContracts.ToArray();
                employeeResultList.Add(result);
            }
            returnValue.Result = employeeResultList.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
예제 #7
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_SSU_1847 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var userAccount = new ORM_USR_Account();
            var result      = userAccount.Load(Connection, Transaction, Parameter.USR_AccountID);

            if (result.Status == FR_Status.Success)
            {
                //Get business participant via userAccount
                var businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, userAccount.BusinessParticipant_RefID);

                //Load person
                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                //Load communication contacts for person
                P_L2CN_GCCfPI_1222 contactsParam = new P_L2CN_GCCfPI_1222();
                contactsParam.PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                var contactsForPersonInfo = cls_Get_ComunicationContacts_for_PersonInfoID.Invoke(Connection, Transaction, contactsParam, securityTicket).Result.ToList();

                if (!Parameter.IsInitialSave)
                {
                    if (Parameter.IsDeleted)
                    {
                        #region Delete

                        var queryApplicationSubscription = new ORM_CMN_Account_ApplicationSubscription.Query();
                        queryApplicationSubscription.Application_RefID = Parameter.ApplicationID;
                        queryApplicationSubscription.Account_RefID     = userAccount.USR_AccountID;
                        queryApplicationSubscription.Tenant_RefID      = securityTicket.TenantID;

                        var foundApplicationSubscription = ORM_CMN_Account_ApplicationSubscription.Query.SoftDelete(Connection, Transaction, queryApplicationSubscription);

                        return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

                        #endregion
                    }

                    #region Edit


                    personInfo.FirstName = Parameter.FirstName_ContactPerson;
                    personInfo.LastName  = Parameter.LastName_ContactPerson;
                    personInfo.Save(Connection, Transaction);

                    var employeeTemp = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                    {
                        BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();

                    if (employeeTemp == null)
                    {
                        var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                        newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                        newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                        newEmployee.StandardFunction          = "APOAdminEmployee";
                        newEmployee.Tenant_RefID = securityTicket.TenantID;
                        newEmployee.Save(Connection, Transaction);
                    }


                    var address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    address.Street_Name     = Parameter.Street_Name;
                    address.Street_Number   = Parameter.Street_Number;
                    address.City_Name       = Parameter.Town;
                    address.City_PostalCode = Parameter.ZIP;
                    address.Save(Connection, Transaction);


                    try
                    {
                        //telephone
                        var telephone = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Phone))
                                        .First().Contacts;

                        if (telephone.Count() == 1)
                        {
                            var contactID = telephone[0].CMN_PER_CommunicationContactID;

                            var contactTelephone = new ORM_CMN_PER_CommunicationContact();
                            contactTelephone.Load(Connection, Transaction, contactID);
                            contactTelephone.Content = Parameter.Contact_Telephone;
                            contactTelephone.Save(Connection, Transaction);
                        }
                    }
                    catch
                    {
                        //Log this
                    }

                    #region CommentedUsefull-PreviousWayOfContactEmailHandling

                    //try
                    //{
                    //    //email
                    //    var email = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Email))
                    //        .First().Contacts;

                    //    if (email.Count() == 1)
                    //    {
                    //        var contactID = email[0].CMN_PER_CommunicationContactID;

                    //        var contactEmail = new ORM_CMN_PER_CommunicationContact();
                    //        contactEmail.Load(Connection, Transaction, contactID);
                    //        contactEmail.Content = Parameter.Contact_Email;
                    //        contactEmail.Save(Connection, Transaction);
                    //    }

                    //}
                    //catch
                    //{

                    //    //Log this
                    //}

                    #endregion

                    #endregion
                }

                #region SaveGroup

                var userAccountToGroup = ORM_USR_Account_2_Group.Query.Search(Connection, Transaction, new ORM_USR_Account_2_Group.Query()
                {
                    USR_Account_RefID = userAccount.USR_AccountID,
                    Tenant_RefID      = securityTicket.TenantID,
                    IsDeleted         = false
                }).SingleOrDefault();


                if (userAccountToGroup == null)
                {
                    var newGroup = new ORM_USR_Account_2_Group();
                    newGroup.AssignmentID       = Guid.NewGuid();
                    newGroup.USR_Account_RefID  = userAccount.USR_AccountID;
                    newGroup.USR_Group_RefID    = Parameter.USR_GroupID;
                    newGroup.Creation_Timestamp = DateTime.Now;
                    newGroup.Tenant_RefID       = securityTicket.TenantID;
                    newGroup.Save(Connection, Transaction);
                }
                else
                {
                    userAccountToGroup.USR_Group_RefID = Parameter.USR_GroupID;
                    userAccountToGroup.Save(Connection, Transaction);
                }

                #endregion

                #region SaveEmployee

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                {
                    BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (employee == null)
                {
                    var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                    newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                    newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                    newEmployee.StandardFunction          = "APOAdminEmployee";
                    newEmployee.Tenant_RefID = securityTicket.TenantID;
                    newEmployee.Save(Connection, Transaction);
                }

                #endregion

                #region CreateOrUpdateContactEmail

                var emailTypeProperty     = EnumUtils.GetEnumDescription(EComunactionContactType.Email);
                var contactEmailTypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query();
                contactEmailTypeQuery.Type         = emailTypeProperty;
                contactEmailTypeQuery.Tenant_RefID = securityTicket.TenantID;
                var contactEmailType = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, contactEmailTypeQuery).FirstOrDefault();

                //Search for default contact email and create it if don't exist

                var defaultContactEmailQuery = new ORM_CMN_PER_CommunicationContact.Query();
                defaultContactEmailQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                defaultContactEmailQuery.Contact_Type     = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                defaultContactEmailQuery.Tenant_RefID     = securityTicket.TenantID;
                var defaultContactEmail = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, defaultContactEmailQuery).FirstOrDefault();

                if (defaultContactEmail == null)
                {
                    defaultContactEmail = new ORM_CMN_PER_CommunicationContact();
                    defaultContactEmail.PersonInfo_RefID        = personInfo.CMN_PER_PersonInfoID;
                    defaultContactEmail.Contact_Type            = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                    defaultContactEmail.IsDefaultForContactType = true;
                    defaultContactEmail.Tenant_RefID            = securityTicket.TenantID;
                }

                defaultContactEmail.Content = Parameter.Contact_Email;
                defaultContactEmail.IsDefaultForContactType = true;
                defaultContactEmail.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                FR_Guid error = new FR_Guid();
                error.ErrorMessage = "No Such ID.";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

            #endregion UserCode
        }
예제 #8
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_DDBID_1653 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here


            P_L6DR_DDBID_1653 param = new P_L6DR_DDBID_1653();
            param.CMN_BPT_BusinessParticipantID = Parameter.CMN_BPT_BusinessParticipantID;

            var drivers = cls_Retrieve_Driver_Info_and_VerCode.Invoke(Connection, Transaction, securityTicket).Result;

            var driver = drivers.FirstOrDefault(x => x.CMN_BPT_BusinessParticipantID == param.CMN_BPT_BusinessParticipantID);

            if (driver != null)
            {
                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                if (driver.CMN_PER_PersonInfoID != Guid.Empty)
                {
                    var result = person.Load(Connection, Transaction, driver.CMN_PER_PersonInfoID);
                    if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    person.IsDeleted = true;
                    person.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    var result = bParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipantID);
                    if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    bParticipant.IsDeleted = true;
                    bParticipant.Save(Connection, Transaction);
                }

                if (driver.Contacts != null)
                {
                    foreach (var parContact in driver.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                        if (parContact.CMN_PER_CommunicationContact_TypeID != Guid.Empty)
                        {
                            var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContact_TypeID);
                            if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                            {
                                var error = new FR_Guid();
                                error.ErrorMessage = "No Such ID";
                                error.Status       = FR_Status.Error_Internal;
                                return(error);
                            }
                            contact.IsDeleted = true;
                            contact.Save(Connection, Transaction);
                        }
                    }
                }

                ORM_CMN_Address adress = new ORM_CMN_Address();
                if (driver.CMN_AddressID != Guid.Empty)
                {
                    var result = adress.Load(Connection, Transaction, driver.CMN_AddressID);
                    if (result.Status != FR_Status.Success || adress.CMN_AddressID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    adress.IsDeleted = true;
                    adress.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();
                if (driver.CMN_BPT_SupplierID != Guid.Empty)
                {
                    var result = supplier.Load(Connection, Transaction, driver.CMN_BPT_SupplierID);
                    if (result.Status != FR_Status.Success || supplier.CMN_BPT_SupplierID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    supplier.IsDeleted = true;
                    supplier.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant asossBParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = asossBParticipant.Load(Connection, Transaction, driver.AssociatedBusinessParticipant_RefID);
                    if (result.Status != FR_Status.Success || asossBParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    asossBParticipant.IsDeleted = true;
                    asossBParticipant.Save(Connection, Transaction);
                }


                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant BusinessParticipant_AssociatedBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = BusinessParticipant_AssociatedBusinessParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID);
                    if (result.Status != FR_Status.Success || BusinessParticipant_AssociatedBusinessParticipant.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    BusinessParticipant_AssociatedBusinessParticipant.IsDeleted = true;
                    BusinessParticipant_AssociatedBusinessParticipant.Save(Connection, Transaction);
                }

                ORM_USR_Account account = new ORM_USR_Account();
                if (driver.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, driver.USR_AccountID);
                    if (result.Status != FR_Status.Success || account.USR_AccountID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    account.IsDeleted = true;
                    account.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                if (driver.USR_Device_AccountCode_UsageHistoryID != Guid.Empty)
                {
                    var result = Device_AccountCode_StatusHistory.Load(Connection, Transaction, driver.USR_Device_AccountCode_UsageHistoryID);
                    if (result.Status != FR_Status.Success || Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    Device_AccountCode_StatusHistory.IsDeleted = true;
                    Device_AccountCode_StatusHistory.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                if (driver.USR_Device_AccountCodeID != Guid.Empty)
                {
                    var result = accountCode.Load(Connection, Transaction, driver.USR_Device_AccountCodeID);
                    if (result.Status != FR_Status.Success || accountCode.USR_Device_AccountCodeID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    accountCode.IsDeleted = true;
                    accountCode.Save(Connection, Transaction);
                }

                var Device_AccountCode_UsageHistoryQuery = new ORM_USR_Device_AccountCode_UsageHistory.Query();
                Device_AccountCode_UsageHistoryQuery.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_UsageHistoryQuery.IsDeleted    = false;
                Device_AccountCode_UsageHistoryQuery.Tenant_RefID = securityTicket.TenantID;

                var historyArray = ORM_USR_Device_AccountCode_UsageHistory.Query.Search(Connection, Transaction, Device_AccountCode_UsageHistoryQuery);
                if (historyArray != null && historyArray.Count > 0)
                {
                    foreach (var historyItem in historyArray)
                    {
                        historyItem.IsDeleted = true;
                        historyItem.Save(Connection, Transaction);
                    }
                }
            }



            return(returnValue);

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

            var ormRevisionGroups = ORM_RES_DUD_RevisionGroup.Query.Search(Connection, Transaction, new ORM_RES_DUD_RevisionGroup.Query()
            {
                RES_DUD_Revision_GroupID = Parameter.RevisionGroupID,
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted = false
            });
            if (ormRevisionGroups.Count == 0)
            {
                return(null);
            }
            var revisionGroup = ormRevisionGroups[0];

            var docHeaderIDs = new List <Guid>();
            var priceIDs     = new List <Guid>();
            returnValue.Result.Currency           = "EUR"; //HARDCODED
            returnValue.Result.Name               = revisionGroup.RevisionGroup_Name;
            returnValue.Result.Comment            = revisionGroup.RevisionGroup_Comment;
            returnValue.Result.SubmittedByAccount = revisionGroup.RevisionGroup_SubmittedBy_Account_RefID;
            returnValue.Result.CreationTimestamp  = revisionGroup.Creation_Timestamp;
            returnValue.Result.RevisionGroupID    = revisionGroup.RES_DUD_Revision_GroupID;

            ORM_RES_RealestateProperty ormRealestateProperty = new ORM_RES_RealestateProperty();
            ormRealestateProperty.Load(Connection, Transaction, revisionGroup.RealestateProperty_RefID);
            ORM_CMN_LOC_Location ormLocation = new ORM_CMN_LOC_Location();
            ormLocation.Load(Connection, Transaction, ormRealestateProperty.RealestateProperty_Location_RefID);
            ORM_CMN_Address ormAddress = new ORM_CMN_Address();
            ormAddress.Load(Connection, Transaction, ormLocation.Address_RefID);

            returnValue.Result.Street_Name     = ormAddress.Street_Name;
            returnValue.Result.Street_Number   = ormAddress.Street_Number;
            returnValue.Result.Country_Name    = ormAddress.Country_Name;
            returnValue.Result.City_Name       = ormAddress.City_Name;
            returnValue.Result.City_PostalCode = ormAddress.City_PostalCode;
            returnValue.Result.City_Region     = ormAddress.City_Region;

            var accountInformation = cls_Get_Account_PersonalInformation_for_AccountID.Invoke(Connection, Transaction, new P_L2AI_GAPIfAI_1627()
            {
                AccountRefID = revisionGroup.RevisionGroup_SubmittedBy_Account_RefID
            }, securityTicket).Result;
            returnValue.Result.SubmittedByAccount_LastName  = accountInformation.LastName;
            returnValue.Result.SubmittedByAccount_FirstName = accountInformation.FirstName;

            var revisions = ORM_RES_DUD_Revision.Query.Search(Connection, Transaction, new ORM_RES_DUD_Revision.Query()
            {
                RevisionGroup_RefID = revisionGroup.RES_DUD_Revision_GroupID,
                IsDeleted           = false,
                Tenant_RefID        = securityTicket.TenantID
            });

            if (revisions == null)
            {
                return(null);
            }

            var populatedRevisions = new List <Revisions>();
            #region retrieve revision full details
            foreach (var revision in revisions)
            {
                Revisions populatedRevision = new Revisions();
                populatedRevision.RevisionID             = revision.RES_DUD_RevisionID;
                populatedRevision.QuestionnaireVersionID = revision.QuestionnaireVersion_RefID;
                populatedRevision.Comment           = revision.Revision_Comment;
                populatedRevision.Title             = revision.Revision_Title;
                populatedRevision.CreationTimestamp = revision.Creation_Timestamp;

                //For each revision in revision group gather and assemble info

                #region submision information
                populatedRevision.ApartmentSubmissionInfo = cls_Get_ApartmentSubmisionInfo_For_RevisionID.Invoke(Connection, Transaction, new P_L5DD_GASIfRID_1007()
                {
                    RevisionID = revision.RES_DUD_RevisionID
                }, securityTicket).Result;
                if (populatedRevision.ApartmentSubmissionInfo != null)
                {
                    var assessments = populatedRevision.ApartmentSubmissionInfo.SelectMany(a => a.ApartmentPropertyAsessments);
                    if (assessments != null)
                    {
                        var         reqActions           = assessments.SelectMany(ass => ass.ApartmentReqActions);
                        List <Guid> pricePerUnitRefIDs   = reqActions.Where(r => r.Action_PricePerUnit_RefID != Guid.Empty).Select(r => r.Action_PricePerUnit_RefID).ToList();
                        List <Guid> effectivePriceRefIDs = reqActions.Where(r => r.EffectivePrice_RefID != Guid.Empty).Select(r => r.EffectivePrice_RefID).ToList();
                        priceIDs.AddRange(pricePerUnitRefIDs);
                        priceIDs.AddRange(effectivePriceRefIDs);
                    }
                }

                populatedRevision.AtticSubmissionInfo = cls_Get_AtticSubmisionInfo_For_RevisionID.Invoke(Connection, Transaction, new P_L5DD_GATTSIFRID_1411()
                {
                    RevisionID = revision.RES_DUD_RevisionID
                }, securityTicket).Result;
                if (populatedRevision.AtticSubmissionInfo != null)
                {
                    var assessments = populatedRevision.AtticSubmissionInfo.SelectMany(a => a.AtticPropertyAsessments);
                    if (assessments != null)
                    {
                        var         reqActions           = assessments.SelectMany(ass => ass.AtticReqActions);
                        List <Guid> pricePerUnitRefIDs   = reqActions.Where(r => r.Action_PricePerUnit_RefID != Guid.Empty).Select(r => r.Action_PricePerUnit_RefID).ToList();
                        List <Guid> effectivePriceRefIDs = reqActions.Where(r => r.EffectivePrice_RefID != Guid.Empty).Select(r => r.EffectivePrice_RefID).ToList();
                        priceIDs.AddRange(pricePerUnitRefIDs);
                        priceIDs.AddRange(effectivePriceRefIDs);
                    }
                }

                populatedRevision.BasementSubmissionInfo = cls_Get_BasementSubmisionInfo_For_RevisionID.Invoke(Connection, Transaction, new P_L5DD_GBSIfRID_1431()
                {
                    RevisionID = revision.RES_DUD_RevisionID
                }, securityTicket).Result;
                if (populatedRevision.BasementSubmissionInfo != null)
                {
                    var assessments = populatedRevision.BasementSubmissionInfo.SelectMany(a => a.BasementPropertyAsessments);
                    if (assessments != null)
                    {
                        var         reqActions           = assessments.SelectMany(ass => ass.BasementReqActions);
                        List <Guid> pricePerUnitRefIDs   = reqActions.Where(r => r.Action_PricePerUnit_RefID != Guid.Empty).Select(r => r.Action_PricePerUnit_RefID).ToList();
                        List <Guid> effectivePriceRefIDs = reqActions.Where(r => r.EffectivePrice_RefID != Guid.Empty).Select(r => r.EffectivePrice_RefID).ToList();
                        priceIDs.AddRange(pricePerUnitRefIDs);
                        priceIDs.AddRange(effectivePriceRefIDs);
                    }
                }

                populatedRevision.FacadeSubmissionInfo = cls_Get_FacadeSubmisionInfo_For_RevisionID.Invoke(Connection, Transaction, new P_L5DD_GFSIfRID_1438()
                {
                    RevisionID = revision.RES_DUD_RevisionID
                }, securityTicket).Result;
                if (populatedRevision.FacadeSubmissionInfo != null)
                {
                    var assessments = populatedRevision.FacadeSubmissionInfo.SelectMany(a => a.FacadePropertyAsessments);
                    if (assessments != null)
                    {
                        var         reqActions           = assessments.SelectMany(ass => ass.FacadeReqActions);
                        List <Guid> pricePerUnitRefIDs   = reqActions.Where(r => r.Action_PricePerUnit_RefID != Guid.Empty).Select(r => r.Action_PricePerUnit_RefID).ToList();
                        List <Guid> effectivePriceRefIDs = reqActions.Where(r => r.EffectivePrice_RefID != Guid.Empty).Select(r => r.EffectivePrice_RefID).ToList();
                        priceIDs.AddRange(pricePerUnitRefIDs);
                        priceIDs.AddRange(effectivePriceRefIDs);
                    }
                }

                populatedRevision.HVACRSubmissionInfo = cls_Get_HVACRSubmisionInfo_For_RevisionID.Invoke(Connection, Transaction, new P_L5DD_GHSIfRID_1448()
                {
                    RevisionID = revision.RES_DUD_RevisionID
                }, securityTicket).Result;
                if (populatedRevision.HVACRSubmissionInfo != null)
                {
                    var assessments = populatedRevision.HVACRSubmissionInfo.SelectMany(a => a.HVACRPropertyAsessments);
                    if (assessments != null)
                    {
                        var         reqActions           = assessments.SelectMany(ass => ass.HVACRReqActions);
                        List <Guid> pricePerUnitRefIDs   = reqActions.Where(r => r.Action_PricePerUnit_RefID != Guid.Empty).Select(r => r.Action_PricePerUnit_RefID).ToList();
                        List <Guid> effectivePriceRefIDs = reqActions.Where(r => r.EffectivePrice_RefID != Guid.Empty).Select(r => r.EffectivePrice_RefID).ToList();
                        priceIDs.AddRange(pricePerUnitRefIDs);
                        priceIDs.AddRange(effectivePriceRefIDs);
                    }
                }

                populatedRevision.OutdoorFascilitySubmissionInfo = cls_Get_OutdoorFascilitySubmisionInfo_For_RevisionID.Invoke(Connection, Transaction, new P_L5DD_GOFSIfRID_1454()
                {
                    RevisionID = revision.RES_DUD_RevisionID
                }, securityTicket).Result;
                if (populatedRevision.OutdoorFascilitySubmissionInfo != null)
                {
                    var assessments = populatedRevision.OutdoorFascilitySubmissionInfo.SelectMany(a => a.OutdoorFacilityAsessments);
                    if (assessments != null)
                    {
                        var         reqActions           = assessments.SelectMany(ass => ass.OutdoorFacilityReqActions);
                        List <Guid> pricePerUnitRefIDs   = reqActions.Where(r => r.Action_PricePerUnit_RefID != Guid.Empty).Select(r => r.Action_PricePerUnit_RefID).ToList();
                        List <Guid> effectivePriceRefIDs = reqActions.Where(r => r.EffectivePrice_RefID != Guid.Empty).Select(r => r.EffectivePrice_RefID).ToList();
                        priceIDs.AddRange(pricePerUnitRefIDs);
                        priceIDs.AddRange(effectivePriceRefIDs);
                    }
                }

                populatedRevision.RoofSubmissionInfo = cls_Get_RoofSubmisionInfo_For_RevisionID.Invoke(Connection, Transaction, new P_L5DD_GRSIfRID_1213()
                {
                    RevisionID = revision.RES_DUD_RevisionID
                }, securityTicket).Result;
                if (populatedRevision.RoofSubmissionInfo != null)
                {
                    var assessments = populatedRevision.RoofSubmissionInfo.SelectMany(a => a.RoofPropertyAsessments);
                    if (assessments != null)
                    {
                        var         reqActions           = assessments.SelectMany(ass => ass.RoofReqActions);
                        List <Guid> pricePerUnitRefIDs   = reqActions.Where(r => r.Action_PricePerUnit_RefID != Guid.Empty).Select(r => r.Action_PricePerUnit_RefID).ToList();
                        List <Guid> effectivePriceRefIDs = reqActions.Where(r => r.EffectivePrice_RefID != Guid.Empty).Select(r => r.EffectivePrice_RefID).ToList();
                        priceIDs.AddRange(pricePerUnitRefIDs);
                        priceIDs.AddRange(effectivePriceRefIDs);
                    }
                }

                populatedRevision.StaircaseSubmissionInfo = cls_Get_StaircaseSubmisionInfo_For_RevisionID.Invoke(Connection, Transaction, new P_L5DD_GASIfRID_1507()
                {
                    RevisionID = revision.RES_DUD_RevisionID
                }, securityTicket).Result;
                if (populatedRevision.StaircaseSubmissionInfo != null)
                {
                    var assessments = populatedRevision.StaircaseSubmissionInfo.SelectMany(a => a.StaircasePropertyAsessments);
                    if (assessments != null)
                    {
                        var         reqActions           = assessments.SelectMany(ass => ass.StaircaseReqActions);
                        List <Guid> pricePerUnitRefIDs   = reqActions.Where(r => r.Action_PricePerUnit_RefID != Guid.Empty).Select(r => r.Action_PricePerUnit_RefID).ToList();
                        List <Guid> effectivePriceRefIDs = reqActions.Where(r => r.EffectivePrice_RefID != Guid.Empty).Select(r => r.EffectivePrice_RefID).ToList();
                        priceIDs.AddRange(pricePerUnitRefIDs);
                        priceIDs.AddRange(effectivePriceRefIDs);
                    }
                }

                #endregion

                #region building information

                populatedRevision.Building = cls_Get_BuildingInfo_for_Building_ID.Invoke(Connection, Transaction, new P_L5BL_GBIfBI_1159()
                {
                    BuildingID = revision.RES_BLD_Building_RefID
                }, securityTicket).Result;

                populatedRevisions.Add(populatedRevision);
                #endregion
            }
            #endregion
            returnValue.Result.Revisions = populatedRevisions.ToArray();


            #region Retrieve Images (documents)

            //retrieve image and price ID's
            foreach (var revision in returnValue.Result.Revisions)
            {
                docHeaderIDs.AddRange(revision.ApartmentSubmissionInfo.Select(x => x.Apartment_DocumentHeader_RefID));
                docHeaderIDs.AddRange(revision.ApartmentSubmissionInfo.SelectMany(x => x.ApartmentPropertyAsessments.Select(s => s.DocumentHeader_RefID)));

                docHeaderIDs.AddRange(revision.AtticSubmissionInfo.Select(x => x.Attic_DocumentHeader_RefID));
                docHeaderIDs.AddRange(revision.AtticSubmissionInfo.SelectMany(x => x.AtticPropertyAsessments.Select(s => s.DocumentHeader_RefID)));

                docHeaderIDs.AddRange(revision.BasementSubmissionInfo.Select(x => x.Basement_DocumentHeader_RefID));
                docHeaderIDs.AddRange(revision.BasementSubmissionInfo.SelectMany(x => x.BasementPropertyAsessments.Select(s => s.DocumentHeader_RefID)));

                docHeaderIDs.AddRange(revision.FacadeSubmissionInfo.Select(x => x.Facade_DocumentHeader_RefID));
                docHeaderIDs.AddRange(revision.FacadeSubmissionInfo.SelectMany(x => x.FacadePropertyAsessments.Select(s => s.DocumentHeader_RefID)));

                docHeaderIDs.AddRange(revision.HVACRSubmissionInfo.Select(x => x.HVACR_DocumentHeader_RefID));
                docHeaderIDs.AddRange(revision.HVACRSubmissionInfo.SelectMany(x => x.HVACRPropertyAsessments.Select(s => s.DocumentHeader_RefID)));

                docHeaderIDs.AddRange(revision.OutdoorFascilitySubmissionInfo.Select(x => x.OutdoorF_DocumentHeader_RefID));
                docHeaderIDs.AddRange(revision.OutdoorFascilitySubmissionInfo.SelectMany(x => x.OutdoorFacilityAsessments.Select(s => s.DocumentHeader_RefID)));

                docHeaderIDs.AddRange(revision.RoofSubmissionInfo.Select(x => x.Roof_DocumentHeader_RefID));
                docHeaderIDs.AddRange(revision.RoofSubmissionInfo.SelectMany(x => x.RoofPropertyAsessments.Select(s => s.DocumentHeader_RefID)));

                docHeaderIDs.AddRange(revision.StaircaseSubmissionInfo.Select(x => x.Staircase_DocumentHeader_RefID));
                docHeaderIDs.AddRange(revision.StaircaseSubmissionInfo.SelectMany(x => x.StaircasePropertyAsessments.Select(s => s.DocumentHeader_RefID)));

                docHeaderIDs.Add(revision.Building.Building_DocumentationStructure_RefID);


                priceIDs.AddRange(revision.ApartmentSubmissionInfo.SelectMany(x => x.ApartmentPropertyAsessments.SelectMany(s => s.ApartmentReqActions.Select(z => z.Action_PricePerUnit_RefID))));
                priceIDs.AddRange(revision.AtticSubmissionInfo.SelectMany(x => x.AtticPropertyAsessments.SelectMany(s => s.AtticReqActions.Select(z => z.Action_PricePerUnit_RefID))));
                priceIDs.AddRange(revision.BasementSubmissionInfo.SelectMany(x => x.BasementPropertyAsessments.SelectMany(s => s.BasementReqActions.Select(z => z.Action_PricePerUnit_RefID))));
                priceIDs.AddRange(revision.FacadeSubmissionInfo.SelectMany(x => x.FacadePropertyAsessments.SelectMany(s => s.FacadeReqActions.Select(z => z.Action_PricePerUnit_RefID))));
                priceIDs.AddRange(revision.HVACRSubmissionInfo.SelectMany(x => x.HVACRPropertyAsessments.SelectMany(s => s.HVACRReqActions.Select(z => z.Action_PricePerUnit_RefID))));
                priceIDs.AddRange(revision.OutdoorFascilitySubmissionInfo.SelectMany(x => x.OutdoorFacilityAsessments.SelectMany(s => s.OutdoorFacilityReqActions.Select(z => z.Action_PricePerUnit_RefID))));
                priceIDs.AddRange(revision.RoofSubmissionInfo.SelectMany(x => x.RoofPropertyAsessments.SelectMany(s => s.RoofReqActions.Select(z => z.Action_PricePerUnit_RefID))));
                priceIDs.AddRange(revision.StaircaseSubmissionInfo.SelectMany(x => x.StaircasePropertyAsessments.SelectMany(s => s.StaircaseReqActions.Select(z => z.Action_PricePerUnit_RefID))));

                priceIDs.AddRange(revision.ApartmentSubmissionInfo.SelectMany(x => x.ApartmentPropertyAsessments.SelectMany(s => s.ApartmentReqActions.Select(z => z.EffectivePrice_RefID))));
                priceIDs.AddRange(revision.AtticSubmissionInfo.SelectMany(x => x.AtticPropertyAsessments.SelectMany(s => s.AtticReqActions.Select(z => z.EffectivePrice_RefID))));
                priceIDs.AddRange(revision.BasementSubmissionInfo.SelectMany(x => x.BasementPropertyAsessments.SelectMany(s => s.BasementReqActions.Select(z => z.EffectivePrice_RefID))));
                priceIDs.AddRange(revision.FacadeSubmissionInfo.SelectMany(x => x.FacadePropertyAsessments.SelectMany(s => s.FacadeReqActions.Select(z => z.EffectivePrice_RefID))));
                priceIDs.AddRange(revision.HVACRSubmissionInfo.SelectMany(x => x.HVACRPropertyAsessments.SelectMany(s => s.HVACRReqActions.Select(z => z.EffectivePrice_RefID))));
                priceIDs.AddRange(revision.OutdoorFascilitySubmissionInfo.SelectMany(x => x.OutdoorFacilityAsessments.SelectMany(s => s.OutdoorFacilityReqActions.Select(z => z.EffectivePrice_RefID))));
                priceIDs.AddRange(revision.RoofSubmissionInfo.SelectMany(x => x.RoofPropertyAsessments.SelectMany(s => s.RoofReqActions.Select(z => z.EffectivePrice_RefID))));
                priceIDs.AddRange(revision.StaircaseSubmissionInfo.SelectMany(x => x.StaircasePropertyAsessments.SelectMany(s => s.StaircaseReqActions.Select(z => z.EffectivePrice_RefID))));


                //docHeaderIDs.Concat(revison.BuildingInfo.BuildingDocuments.Select(x => x.Building_DocumentationStructure_RefID));
            }


            var docHeaders = new List <L3DO_GDfDH_1133>();

            foreach (var docHeaderID in docHeaderIDs)
            {
                if (docHeaderID == Guid.Empty)
                {
                    continue;
                }
                var documentRevisions = cls_Get_Documents_for_DHeaderID.Invoke(Connection, Transaction, new P_L3DO_GDfDH_1133()
                {
                    DHeaderID = docHeaderID
                }, securityTicket).Result;
                if (documentRevisions == null || documentRevisions.Count() == 0)
                {
                    continue;
                }

                docHeaders.AddRange(documentRevisions);
            }
            returnValue.Result.Images = docHeaders.ToArray();
            #endregion

            #region Retrieve Prices
            var dbPrices = new List <L2PR_GPIfP_1135>();
            foreach (var priceID in priceIDs)
            {
                if (priceID == Guid.Empty)
                {
                    continue;
                }
                var priceValue = cls_Get_PriceInformation_For_PriceID.Invoke(Connection, Transaction, new P_L2PR_GPIfP_1135()
                {
                    PriceID = priceID
                }, securityTicket).Result;
                if (priceValue == null)
                {
                    continue;
                }
                dbPrices.Add(priceValue);
                //Find EU

                //if (string.Equals(priceValue.ISO4127, "EUR", StringComparison.OrdinalIgnoreCase))
                //    {
                //        dbPrices.Add(priceValue);
                //        break;
                //    }
                //    else
                //    {
                //        dbPrices.Add(priceValue);
                //        break;
                //    }
            }
            returnValue.Result.Prices = dbPrices.ToArray();

            #endregion

            return(returnValue);

            #endregion UserCode
        }
예제 #10
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SFE_1524 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();



            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name     = Parameter.City_Name;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.Country_Name  = Parameter.Country_Name;
            address.Province_Name = Parameter.Province_Name;
            address.Tenant_RefID  = Parameter.TenantID;
            address.Save(Connection, Transaction);

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

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = Parameter.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.BirthDate     = Parameter.BirthDate;
            person.Save(Connection, Transaction);

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = Parameter.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();


            CSV2Core.DlTrace.Trace("Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = Parameter.TenantID;

            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("after save Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            CSV2Core.DlTrace.Trace("employee.Status_IsAlreadySaved " + employee.Status_IsAlreadySaved);

            ORM_CMN_BPT_EMP_EmploymentRelationship employeeRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_WorkingContractID != Guid.Empty)
            {
                var result = employeeRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_WorkingContractID);
                if (result.Status != FR_Status.Success || employeeRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employeeRelationship.Work_StartDate = Parameter.Work_StartDate;
            employeeRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employeeRelationship.Tenant_RefID   = Parameter.TenantID;
            employeeRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employeeRelationship.Save(Connection, Transaction);



            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, Parameter.USR_AccountID);
                account.USR_AccountID             = Parameter.USR_AccountID;
                account.Username                  = Parameter.username;
                account.DefaultLanguage_RefID     = Parameter.LanguageID;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID              = Parameter.TenantID;
                account.Save(Connection, Transaction);

                var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                personToAccountQuery.IsDeleted         = false;
                var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                if (personToAccounts.Count != 0)
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }

                if (Parameter.Rights != null)
                {
                    foreach (var rightParam in Parameter.Rights)
                    {
                        var right = new ORM_USR_Account_FunctionLevelRight();
                        if (rightParam.RightID != Guid.Empty)
                        {
                            var result = right.Load(Connection, Transaction, rightParam.RightID);
                            if (result.Status != FR_Status.Success || right.USR_Account_FunctionLevelRightID == Guid.Empty)
                            {
                                right.USR_Account_FunctionLevelRightID = rightParam.RightID;
                                right.Tenant_RefID = Parameter.TenantID;
                                right.RightName    = rightParam.RightName;
                                right.FunctionLevelRights_Group_RefID = Guid.Empty;
                                right.Save(Connection, Transaction);
                            }
                        }

                        var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                        right2account.Account_RefID            = account.USR_AccountID;
                        right2account.FunctionLevelRight_RefID = rightParam.RightID;
                        right2account.Tenant_RefID             = Parameter.TenantID;
                        right2account.Save(Connection, Transaction);
                    }
                }
            }

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

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

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name       = Parameter.City_Name;
            address.Street_Name     = Parameter.Street_Name;
            address.Street_Number   = Parameter.Street_Number;
            address.Country_Name    = Parameter.Country_Name;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success address");
            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = securityTicket.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.ProfileImage_Document_RefID = Parameter.ImageID;
            person.BirthDate        = Parameter.BirthDate;
            person.NumberOfChildren = Parameter.TaxInfoParameter != null ? Parameter.TaxInfoParameter.NumberOfChildren : 0;
            person.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success persopm");

            var contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            contactQuery.IsDeleted        = false;
            var deleteContacts = ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, contactQuery);
            foreach (var parContact in Parameter.Contacts)
            {
                ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                if (parContact.CMN_PER_CommunicationContactID != Guid.Empty)
                {
                    var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContactID);
                    if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                }
                contact.Content          = parContact.Content;
                contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                contact.Tenant_RefID     = securityTicket.TenantID;
                contact.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contact.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success contact");
            }

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            CSV2Core.DlTrace.Trace("success bpart");


            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = securityTicket.TenantID;
            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employee");


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

            bool resignationDateChanged = false;
            if (employmentRelationship.Work_EndDate != Parameter.Work_EndDate)
            {
                resignationDateChanged = true;
            }

            employmentRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employmentRelationship.Tenant_RefID   = securityTicket.TenantID;
            employmentRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employmentRelationship.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employmentRelationship");

            if (Parameter.Work_EndDate.Ticks != 0)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query empRelationShipToWorkingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                empRelationShipToWorkingContractQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                empRelationShipToWorkingContractQuery.Tenant_RefID = securityTicket.TenantID;
                empRelationShipToWorkingContractQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> workingContractAssignments = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, empRelationShipToWorkingContractQuery);
                foreach (var workingContractAssignment in workingContractAssignments)
                {
                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    if (workingContractAssignment.WorkingContract_RefID != Guid.Empty)
                    {
                        var result = workingContract.Load(Connection, Transaction, workingContractAssignment.WorkingContract_RefID);
                        if (result.Status != FR_Status.Success || workingContract.CMN_BPT_EMP_WorkingContractID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    if (workingContract.Contract_EndDate.Ticks == 0 || workingContract.Contract_EndDate.Ticks > Parameter.Work_EndDate.Ticks)
                    {
                        workingContract.Contract_EndDate         = Parameter.Work_EndDate;
                        workingContract.IsContractEndDateDefined = true;
                        workingContract.Save(Connection, Transaction);
                    }
                }
            }

            var activeTimeFrame = cls_Get_Active_CalculationTimeFrame.Invoke(Connection, Transaction, securityTicket).Result;

            var timeframes   = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            var resultFrames = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year == employmentRelationship.Work_StartDate.Year).ToList();
            if (resultFrames.Count == 0)
            {
                var newFrame    = new ORM_CMN_CAL_CalculationTimeframe();
                int currentYear = Parameter.Work_StartDate.Year;
                while (currentYear < activeTimeFrame.CalculationTimeframe_StartDate.Year)
                {
                    if (!timeframes.Any(i => i.CalculationTimeframe_StartDate.Year == currentYear))
                    {
                        newFrame.CalculationTimeframe_StartDate        = new DateTime(currentYear, 1, 1);
                        newFrame.CalculationTimeframe_EstimatedEndDate = new DateTime(currentYear, 12, 31);
                        newFrame.Tenant_RefID = securityTicket.TenantID;
                        newFrame.Save(Connection, Transaction);
                        newFrame = new ORM_CMN_CAL_CalculationTimeframe();
                    }
                    currentYear++;

                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    relationshipFrame.CalculationTimeframe_RefID   = newFrame.CMN_CAL_CalculationTimeframeID;
                    relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                    relationshipFrame.Save(Connection, Transaction);
                }
            }
            else
            {
                timeframes = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year < activeTimeFrame.CalculationTimeframe_StartDate.Year && i.CalculationTimeframe_StartDate.Year >= employmentRelationship.Work_StartDate.Year).ToList();
                foreach (var timeframe in timeframes)
                {
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query relationshipFrameQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query();
                    relationshipFrameQuery.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                    relationshipFrameQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrameQuery.Tenant_RefID = securityTicket.TenantID;
                    List <ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe> oldContractFrames = ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query.Search(Connection, Transaction, relationshipFrameQuery);
                    if (oldContractFrames.Count == 0)
                    {
                        ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                        relationshipFrame.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                        relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                        relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                        relationshipFrame.Save(Connection, Transaction);
                    }
                }
            }



            P_L5EM_GAERCTFFE_1405 timeFrameParam = new P_L5EM_GAERCTFFE_1405();
            timeFrameParam.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            L5EM_GAERCTFFE_1405 employeeTimeFrame = cls_Get_Active_EmployeeRelationshipTimeFrame_For_EmployeeID.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result;
            if (employeeTimeFrame == null)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe timeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                timeFrame.CalculationTimeframe_RefID   = activeTimeFrame.CMN_CAL_CalculationTimeframeID;
                timeFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                timeFrame.Tenant_RefID = securityTicket.TenantID;
                timeFrame.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success timeFrame");
            }

            //save employee professions
            P_L5EM_SEP_1447 saveProfessionsPar = new P_L5EM_SEP_1447();
            saveProfessionsPar.Employee_RefID    = employee.CMN_BPT_EMP_EmployeeID;
            saveProfessionsPar.FunctionHistories = Parameter.FunctionHistories;
            cls_Save_EmployeeFunctionHistory.Invoke(Connection, Transaction, saveProfessionsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success employee function history");

            //save workplace histories
            P_L5EM_SWPH_1625 saveWorkplaceHistoryPar = new P_L5EM_SWPH_1625();
            saveWorkplaceHistoryPar.Employee_RefID     = employee.CMN_BPT_EMP_EmployeeID;
            saveWorkplaceHistoryPar.WorkplaceHistories = Parameter.WorkplaceHistories;
            cls_Save_WorkplaceHistories.Invoke(Connection, Transaction, saveWorkplaceHistoryPar, securityTicket);
            CSV2Core.DlTrace.Trace("success workplaceHistories");

            P_L5EM_SUED_1648 saveDocuments = new P_L5EM_SUED_1648();
            saveDocuments.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveDocuments.Documents      = Parameter.Documents;
            cls_Save_Uploaded_Employee_Document.Invoke(Connection, Transaction, saveDocuments, securityTicket);
            CSV2Core.DlTrace.Trace("success documents");

            P_L5EM_SEQS_0959 saveSkillsPar = new P_L5EM_SEQS_0959();
            saveSkillsPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveSkillsPar.Skills         = Parameter.Skills;
            cls_Save_Employee_QualificationSkills.Invoke(Connection, Transaction, saveSkillsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success skills");

            CSV2Core.DlTrace.Trace("AccountID :" + Parameter.USR_AccountID);

            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                CSV2Core.DlTrace.Trace("success param");

                ORM_USR_Account account = new ORM_USR_Account();
                if (Parameter.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, Parameter.USR_AccountID);
                    if (account.USR_AccountID == Guid.Empty)
                    {
                        account.USR_AccountID = Guid.NewGuid();
                        account.AccountType   = 2;
                    }
                    account.Username = Parameter.username;
                    account.DefaultLanguage_RefID     = Parameter.LanguageID;
                    account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                    account.Tenant_RefID = securityTicket.TenantID;
                    account.Save(Connection, Transaction);


                    var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                    personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                    personToAccountQuery.IsDeleted         = false;
                    var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                    if (personToAccounts.Count != 0)
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                }



                if (Parameter.Rights != null)
                {
                    foreach (var rightsParam in Parameter.Rights)
                    {
                        if (rightsParam.RightAssinmentID == Guid.Empty && rightsParam.RightID != Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            right2account.Account_RefID            = Parameter.USR_AccountID;
                            right2account.FunctionLevelRight_RefID = rightsParam.RightID;
                            right2account.Tenant_RefID             = securityTicket.TenantID;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right: " + right2account.FunctionLevelRight_RefID);
                        }

                        if (rightsParam.RightAssinmentID != Guid.Empty && rightsParam.RightID == Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            if (rightsParam.RightAssinmentID != Guid.Empty)
                            {
                                var result = right2account.Load(Connection, Transaction, rightsParam.RightAssinmentID);
                                if (result.Status != FR_Status.Success || right2account.AssignmentID == Guid.Empty)
                                {
                                    var error = new FR_Guid();
                                    error.ErrorMessage = "No Such ID";
                                    error.Status       = FR_Status.Error_Internal;
                                    return(error);
                                }
                            }
                            right2account.IsDeleted = true;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right2Acc: " + right2account.FunctionLevelRight_RefID);
                        }
                    }
                }
            }

            CSV2Core.DlTrace.Trace("emp id wtf " + Parameter.CMN_BPT_EMP_EmployeeID);

            if (Parameter.CMN_BPT_EMP_EmployeeID == Guid.Empty || resignationDateChanged)
            {
                var enterpriseService          = InfrastructureFactory.CreateEnterpriseService();
                KeyPerformanceIndicator action = new KeyPerformanceIndicator();
                action.PerformedByAccountID     = securityTicket.AccountID;
                action.PerformedByApplicationID = Parameter.ApplicationID;
                action.PerformedOn               = DateTime.Now;
                action.PerformedByTenantID       = securityTicket.TenantID;
                action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b");
                action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Where(i => i.Work_EndDate.Ticks == 0 || i.Work_EndDate.Ticks > DateTime.Now.Ticks).ToArray().Length;

                var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM);
                // ServerLog.Instance.Info("Enterprise message sending " + (result.Code == 200 ? "successful" : "failed"));
                CSV2Core.DlTrace.Trace("success send kpi");
            }

            Parameter.TaxInfoParameter.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.TaxInfoParameter.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_TaxInformation.Invoke(Connection, Transaction, Parameter.TaxInfoParameter, securityTicket);
            cls_Save_Employee_BankAccount.Invoke(Connection, Transaction, Parameter.BankAccountParameter, securityTicket);
            Parameter.SocialSecurity.CMN_PER_PersonInfoID          = person.CMN_PER_PersonInfoID;
            Parameter.SocialSecurity.CMN_BPT_EMP_EmployeeID        = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.SocialSecurity.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_SocialSecurity.Invoke(Connection, Transaction, Parameter.SocialSecurity, securityTicket);

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

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



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



            var address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name = Parameter.City_Name;
            address.City_AdministrativeDistrict = Parameter.City_AdministrativeDistrict;
            address.City_PostalCode             = Parameter.City_PostalCode;
            address.City_Region   = Parameter.City_Region;
            address.Country_Name  = Parameter.Country_Name;
            address.Province_Name = Parameter.Province_Name;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.Tenant_RefID  = securityTicket.TenantID;
            address.Save(Connection, Transaction);

            item.Default_BillingAddress_RefID  = address.CMN_AddressID;
            item.Default_ShippingAddress_RefID = address.CMN_AddressID;
            item.Tenant_RefID                   = securityTicket.TenantID;
            item.Default_FaxNumber              = Parameter.Default_FaxNumber;
            item.Default_PhoneNumber            = Parameter.Default_PhoneNumber;
            item.Office_Name                    = Parameter.OfficeName;
            item.Office_Description             = Parameter.OfficeDescription;
            item.Office_ShortName               = Parameter.OfficeShortName;
            item.CMN_CAL_CalendarInstance_RefID = Parameter.CMN_CAL_CalendarInstance_RefID;
            item.Region_RefID                   = Parameter.Region_RefID;
            item.Country_RefID                  = Parameter.Country_RefID;

            ORM_CMN_CAL_CalendarInstance calendar = new ORM_CMN_CAL_CalendarInstance();
            if (Parameter.CMN_CAL_CalendarInstance_RefID != Guid.Empty)
            {
                var result = calendar.Load(Connection, Transaction, Parameter.CMN_CAL_CalendarInstance_RefID);
                if (result.Status != FR_Status.Success || calendar.CMN_CAL_CalendarInstanceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            calendar.WeekStartsOnDay = 1;
            calendar.Save(Connection, Transaction);
            item.CMN_CAL_CalendarInstance_RefID = calendar.CMN_CAL_CalendarInstanceID;
            item.Save(Connection, Transaction);



            ORM_CMN_STR_Office_2_CostCenter whereCC2OInstance = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_STR_Office_2_CostCenter>();
            whereCC2OInstance.Office_RefID = Parameter.CMN_STR_OfficeID;
            CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereCC2OInstance);
            if (Parameter.Costcenter_RefID != Guid.Empty)
            {
                var cc2o = new ORM_CMN_STR_Office_2_CostCenter();
                cc2o.CostCenter_RefID = Parameter.Costcenter_RefID;
                cc2o.IsDefault        = true;
                cc2o.IsDeleted        = false;
                cc2o.Tenant_RefID     = securityTicket.TenantID;
                cc2o.Office_RefID     = item.CMN_STR_OfficeID;
                cc2o.Save(Connection, Transaction);
            }
            var query1 = new ORM_CMN_STR_Office_ResponsiblePerson.Query();
            query1.Tenant_RefID = securityTicket.TenantID;
            query1.Office_RefID = item.CMN_STR_OfficeID;
            var res = ORM_CMN_STR_Office_ResponsiblePerson.Query.SoftDelete(Connection, Transaction, query1);
            if (Parameter.ResponsiblePerson != null && Parameter.ResponsiblePerson.Length > 0)
            {
                foreach (P_L5OF_SO_1428_ResponsiblePerson obj in Parameter.ResponsiblePerson)
                {
                    ORM_CMN_STR_Office_ResponsiblePerson person = new ORM_CMN_STR_Office_ResponsiblePerson();
                    if (obj.AssignmentID != Guid.Empty)
                    {
                        var result = calendar.Load(Connection, Transaction, obj.AssignmentID);
                        if (result.Status != FR_Status.Success || person.CMN_STR_Office_ResponsiblePersonID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    if (obj.AssignmentID != Guid.Empty)
                    {
                        person.IsDeleted = true;
                    }
                    else
                    {
                        person.CMN_BPT_EMP_Employee_RefID = obj.ResponsibleEmployeeID;
                        person.Office_RefID = item.CMN_STR_OfficeID;
                        person.Tenant_RefID = securityTicket.TenantID;
                    }

                    person.Save(Connection, Transaction);
                }
            }

            return(new FR_Guid(item.CMN_STR_OfficeID));

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_SMSAFP_1547 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            P_L6PA_GMSPfID_1538 getPatientParam = new P_L6PA_GMSPfID_1538();
            getPatientParam.HEC_PatientID = Parameter.HEC_PatientID;
            L6PA_GMSPfID_1538 patient = cls_Get_MS_Patients_For_ID.Invoke(Connection, Transaction, getPatientParam, securityTicket).Result;

            if (patient == null)
            {
                var error = new FR_Guid();
                error.ErrorMessage = "No Such ID";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            ORM_CMN_PER_PersonInfo_2_Address.Query query = new ORM_CMN_PER_PersonInfo_2_Address.Query();
            query.CMN_PER_PersonInfo_RefID = patient.CMN_PER_PersonInfoID;
            query.Tenant_RefID             = securityTicket.TenantID;
            query.IsDeleted = false;
            var queryRes = ORM_CMN_PER_PersonInfo_2_Address.Query.Search(Connection, Transaction, query);

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.Street_Name     = Parameter.Street_Name;
            address.Street_Number   = Parameter.Street_Number;
            address.City_Name       = Parameter.City_Name;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.Save(Connection, Transaction);

            ORM_CMN_PER_PersonInfo_2_Address assignment = queryRes.FirstOrDefault(a => a.CMN_Address_RefID == Parameter.CMN_AddressID);
            if (assignment == null)
            {
                assignment = new ORM_CMN_PER_PersonInfo_2_Address();

                assignment.CMN_Address_RefID        = address.CMN_AddressID;
                assignment.CMN_PER_PersonInfo_RefID = patient.CMN_PER_PersonInfoID;
                assignment.Tenant_RefID             = securityTicket.TenantID;
                if (queryRes.Count == 0)
                {
                    assignment.IsPrimary = true;
                }
                assignment.SequenceNumber = queryRes.Count + 1;
            }

            assignment.Save(Connection, Transaction);

            returnValue.Result = address.CMN_AddressID;
            return(returnValue);

            #endregion UserCode
        }
예제 #14
0
        protected static FR_L5OF_GOFT_1157_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5OF_GOFT_1157_Array();
            ORM_CMN_STR_Office.Query officesQuery = new ORM_CMN_STR_Office.Query();
            officesQuery.IsDeleted    = false;
            officesQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_STR_Office> officesResult     = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officesQuery);
            List <L5OF_GOFT_1157>     officesResultList = new List <L5OF_GOFT_1157>();
            foreach (var office in officesResult)
            {
                L5OF_GOFT_1157 result = new L5OF_GOFT_1157();
                var            item   = new ORM_CMN_STR_Office();

                var resultOffice = item.Load(Connection, Transaction, office.CMN_STR_OfficeID);
                if (resultOffice.Status != FR_Status.Success || item.CMN_STR_OfficeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(null);
                }

                result.CMN_CAL_CalendarInstance_RefID = item.CMN_CAL_CalendarInstance_RefID;
                result.CMN_STR_OfficeID             = item.CMN_STR_OfficeID;
                result.Country_RefID                = item.Country_RefID;
                result.Default_FaxNumber            = item.Default_FaxNumber;
                result.Default_PhoneNumber          = item.Default_PhoneNumber;
                result.Office_ShortName             = item.Office_ShortName;
                result.OfficeDescription            = item.Office_Description;
                result.OfficeName                   = item.Office_Name;
                result.Region_RefID                 = item.Region_RefID;
                result.BillingAddress_CMN_AddressID = item.Default_BillingAddress_RefID;



                var address    = new ORM_CMN_Address();
                var resultItem = address.Load(Connection, Transaction, item.Default_BillingAddress_RefID);
                if (resultItem.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(null);
                }

                result.BillingAddress_City_Name = address.City_Name;
                result.BillingAddress_City_AdministrativeDistrict = address.City_AdministrativeDistrict;
                result.BillingAddress_City_PostalCode             = address.City_PostalCode;
                result.BillingAddress_City_Region     = address.City_Region;
                result.BillingAddress_Country_Name    = address.Country_Name;
                result.BillingAddress_Province_Name   = address.Province_Name;
                result.BillingAddress_Street_Name     = address.Street_Name;
                result.BillingAddress_Street_Number   = address.Street_Number;
                result.BillingAddress_Country_ISOCode = address.Country_ISOCode;



                ORM_CMN_STR_Office_2_CostCenter.Query officeToCostcenterQuery = new  ORM_CMN_STR_Office_2_CostCenter.Query();
                officeToCostcenterQuery.Office_RefID = office.CMN_STR_OfficeID;
                officeToCostcenterQuery.Tenant_RefID = securityTicket.TenantID;
                officeToCostcenterQuery.IsDeleted    = false;
                List <ORM_CMN_STR_Office_2_CostCenter> officeToCostcenterList = ORM_CMN_STR_Office_2_CostCenter.Query.Search(Connection, Transaction, officeToCostcenterQuery);
                if (officeToCostcenterList.Count != 0)
                {
                    L5OF_GOFT_1157_Costcenter costCenter     = new L5OF_GOFT_1157_Costcenter();
                    ORM_CMN_STR_CostCenter    costCenterItem = new ORM_CMN_STR_CostCenter();
                    costCenterItem.Load(Connection, Transaction, officeToCostcenterList[0].CostCenter_RefID);
                    if (!costCenterItem.IsDeleted)
                    {
                        costCenter.AssignmentID         = officeToCostcenterList[0].AssignmentID;
                        costCenter.CMN_STR_CostCenterID = officeToCostcenterList[0].CostCenter_RefID;
                        costCenter.CostcenterName       = costCenterItem.Name;
                        costCenter.InternalID           = costCenterItem.InternalID;
                        result.Costcenter = costCenter;
                    }
                }
                var responsiblePersonsQuery = new ORM_CMN_STR_Office_ResponsiblePerson.Query();
                responsiblePersonsQuery.Tenant_RefID = securityTicket.TenantID;
                responsiblePersonsQuery.Office_RefID = item.CMN_STR_OfficeID;
                responsiblePersonsQuery.IsDeleted    = false;
                var responsiblePersonsList = ORM_CMN_STR_Office_ResponsiblePerson.Query.Search(Connection, Transaction, responsiblePersonsQuery);
                List <L5OF_GOFT_1157_ResponsiblePersons> responsiblePresonsResultList = new List <L5OF_GOFT_1157_ResponsiblePersons>();
                foreach (var responsiblePerson in responsiblePersonsList)
                {
                    L5OF_GOFT_1157_ResponsiblePersons responsiblePersonResult = new L5OF_GOFT_1157_ResponsiblePersons();
                    responsiblePersonResult.CMN_BPT_EMP_EmployeeID             = responsiblePerson.CMN_BPT_EMP_Employee_RefID;
                    responsiblePersonResult.CMN_STR_Office_ResponsiblePersonID = responsiblePerson.CMN_STR_Office_ResponsiblePersonID;

                    ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                    employee.Load(Connection, Transaction, responsiblePerson.CMN_BPT_EMP_Employee_RefID);

                    ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                    bParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                    ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                    person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                    responsiblePersonResult.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
                    responsiblePersonResult.FirstName = person.FirstName;
                    responsiblePersonResult.LastName  = person.LastName;
                    responsiblePresonsResultList.Add(responsiblePersonResult);
                }
                result.Managers = responsiblePresonsResultList.ToArray();
                officesResultList.Add(result);
            }
            returnValue.Result = officesResultList.ToArray();
            //Put your code here
            return(returnValue);

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

            var revisionGroupList = new List <L6DD_GRGIfRPI_1752>();

            var ormRevisionGroups = ORM_RES_DUD_RevisionGroup.Query.Search(Connection, Transaction, new ORM_RES_DUD_RevisionGroup.Query()
            {
                IsDeleted = false,
                RealestateProperty_RefID = Parameter.RealestatePropertyID,
                Tenant_RefID             = securityTicket.TenantID
            });

            foreach (var revGroup in ormRevisionGroups)
            {
                var revisionGroup = new L6DD_GRGIfRPI_1752();

                revisionGroup.Comment           = revGroup.RevisionGroup_Comment;
                revisionGroup.CreationTimestamp = revGroup.Creation_Timestamp;
                revisionGroup.Name = revGroup.RevisionGroup_Name;
                revisionGroup.SubmittedByAccount   = revisionGroup.SubmittedByAccount;
                revisionGroup.RealestatePropertyID = Parameter.RealestatePropertyID;
                revisionGroup.RevisionGroupID      = revGroup.RES_DUD_Revision_GroupID;

                //Find address information

                ORM_RES_RealestateProperty ormRealestateProperty = new ORM_RES_RealestateProperty();
                ormRealestateProperty.Load(Connection, Transaction, revGroup.RealestateProperty_RefID);
                ORM_CMN_LOC_Location ormLocation = new ORM_CMN_LOC_Location();
                ormLocation.Load(Connection, Transaction, ormRealestateProperty.RealestateProperty_Location_RefID);
                ORM_CMN_Address ormAddress = new ORM_CMN_Address();
                ormAddress.Load(Connection, Transaction, ormLocation.Address_RefID);

                revisionGroup.Street_Name     = ormAddress.Street_Name;
                revisionGroup.Street_Number   = ormAddress.Street_Number;
                revisionGroup.Country_Name    = ormAddress.Country_Name;
                revisionGroup.City_Name       = ormAddress.City_Name;
                revisionGroup.City_PostalCode = ormAddress.City_PostalCode;
                revisionGroup.City_Region     = ormAddress.City_Region;


                var accountInformation = cls_Get_Account_PersonalInformation_for_AccountID.Invoke(Connection, Transaction, new P_L2AI_GAPIfAI_1627()
                {
                    AccountRefID = revGroup.RevisionGroup_SubmittedBy_Account_RefID
                }, securityTicket).Result;
                revisionGroup.SubmittedByAccount_LastName  = accountInformation.LastName;
                revisionGroup.SubmittedByAccount_FirstName = accountInformation.FirstName;


                var revisionList = new List <L6DD_GRGIfRPI_1752_Revision>();

                var omrRevisions = ORM_RES_DUD_Revision.Query.Search(Connection, Transaction, new ORM_RES_DUD_Revision.Query()
                {
                    IsDeleted           = false,
                    RevisionGroup_RefID = revGroup.RES_DUD_Revision_GroupID,
                    Tenant_RefID        = securityTicket.TenantID
                });


                foreach (var rev in omrRevisions)
                {
                    var ormBuildings = ORM_RES_BLD_Building.Query.Search(Connection, Transaction, new ORM_RES_BLD_Building.Query()
                    {
                        IsDeleted          = false,
                        RES_BLD_BuildingID = rev.RES_BLD_Building_RefID,
                        Tenant_RefID       = securityTicket.TenantID
                    });

                    var revision = new L6DD_GRGIfRPI_1752_Revision();
                    revision.BuildingID    = rev.RES_BLD_Building_RefID;
                    revision.RevisionID    = rev.RES_DUD_RevisionID;
                    revision.RevisionTitle = rev.Revision_Title;
                    revision.BuildingName  = ormBuildings[0].Building_Name;

                    revisionList.Add(revision);
                }
                revisionGroup.Revisions = revisionList.ToArray();
                revisionGroupList.Add(revisionGroup);
            }

            returnValue.Result = revisionGroupList.ToArray();

            return(returnValue);

            #endregion UserCode
        }
예제 #16
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2OF_SOA_1410 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            if (Parameter.IsDefaultAddress)
            {
                //set previous flags as non default
                ORM_CMN_STR_Office_Address.Query.Update(Connection, Transaction,
                                                        new ORM_CMN_STR_Office_Address.Query()
                {
                    Office_RefID      = Parameter.OfficeID,
                    IsDefault         = true,
                    IsShippingAddress = Parameter.IsShippingAddress,
                    IsBillingAddress  = Parameter.IsBillingAddress
                },
                                                        new ORM_CMN_STR_Office_Address.Query()
                {
                    IsDefault = false
                }
                                                        );
            }

            var addressID = Guid.Empty;
            if (Parameter.AddressID == Guid.Empty)
            {
                //Create
                var saveAddressParam = new P_L2AD_SA_1755();
                saveAddressParam.CMN_AddressID   = Parameter.Address_Save.CMN_AddressID;
                saveAddressParam.CareOf          = Parameter.Address_Save.CareOf;
                saveAddressParam.Street_Name     = Parameter.Address_Save.Street_Name;
                saveAddressParam.Street_Number   = Parameter.Address_Save.Street_Number;
                saveAddressParam.City_PostalCode = Parameter.Address_Save.City_PostalCode;
                saveAddressParam.City_Name       = Parameter.Address_Save.City_Name;
                saveAddressParam.Country_Name    = Parameter.Address_Save.Country_Name;
                saveAddressParam.Country_ISOCode = Parameter.Address_Save.Country_ISOCode;
                addressID = cls_Save_Address.Invoke(Connection, Transaction, saveAddressParam, securityTicket).Result;

                var OfficeAddress = new ORM_CMN_STR_Office_Address();

                OfficeAddress.CMN_Address_RefID     = addressID;
                OfficeAddress.Office_RefID          = Parameter.OfficeID;
                OfficeAddress.IsBillingAddress      = Parameter.IsBillingAddress;
                OfficeAddress.IsShippingAddress     = Parameter.IsShippingAddress;
                OfficeAddress.IsSpecialAddress      = Parameter.IsSpecialAddress;
                OfficeAddress.IfSpecialAddress_Name = Parameter.IsSpecialAddress_Name;
                OfficeAddress.IsDefault             = Parameter.IsDefaultAddress;
                OfficeAddress.Tenant_RefID          = securityTicket.TenantID;
                OfficeAddress.Save(Connection, Transaction);
            }
            else
            {
                //Update
                addressID = Parameter.AddressID;

                var address = new ORM_CMN_Address();
                address.Load(Connection, Transaction, Parameter.AddressID);
                address.CareOf          = Parameter.Address_Save.CareOf;
                address.Street_Name     = Parameter.Address_Save.Street_Name;
                address.Street_Number   = Parameter.Address_Save.Street_Number;
                address.City_PostalCode = Parameter.Address_Save.City_PostalCode;
                address.City_Name       = Parameter.Address_Save.City_Name;
                address.Country_Name    = Parameter.Address_Save.Country_Name;
                address.Country_ISOCode = Parameter.Address_Save.Country_ISOCode;
                address.Save(Connection, Transaction);

                var queryOfficeAddress = new ORM_CMN_STR_Office_Address.Query();
                queryOfficeAddress.CMN_Address_RefID = Parameter.AddressID;
                queryOfficeAddress.Office_RefID      = Parameter.OfficeID;
                queryOfficeAddress.IsDeleted         = false;
                var officeAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, queryOfficeAddress).FirstOrDefault();

                officeAddress.IsDefault             = Parameter.IsDefaultAddress;
                officeAddress.IsBillingAddress      = Parameter.IsBillingAddress;
                officeAddress.IsShippingAddress     = Parameter.IsShippingAddress;
                officeAddress.IsSpecialAddress      = Parameter.IsSpecialAddress;
                officeAddress.IfSpecialAddress_Name = Parameter.IsSpecialAddress_Name;

                officeAddress.Save(Connection, Transaction);
            }


            #region Update DefaultAdresses

            var defaultShippingAddressQuery = new ORM_CMN_STR_Office_Address.Query();
            defaultShippingAddressQuery.Office_RefID      = Parameter.OfficeID;
            defaultShippingAddressQuery.IsDeleted         = false;
            defaultShippingAddressQuery.IsDefault         = true;
            defaultShippingAddressQuery.IsShippingAddress = true;
            var defaultShippingAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, defaultShippingAddressQuery).SingleOrDefault();

            var defaultBillingAddressQuery = new ORM_CMN_STR_Office_Address.Query();
            defaultBillingAddressQuery.Office_RefID     = Parameter.OfficeID;
            defaultBillingAddressQuery.IsDeleted        = false;
            defaultBillingAddressQuery.IsDefault        = true;
            defaultBillingAddressQuery.IsBillingAddress = true;
            var defaultBillingAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, defaultBillingAddressQuery).SingleOrDefault();

            var office = new ORM_CMN_STR_Office();
            office.Load(Connection, Transaction, Parameter.OfficeID);

            office.Default_BillingAddress_RefID  = (defaultBillingAddress != null) ? defaultBillingAddress.CMN_Address_RefID : Guid.Empty;
            office.Default_ShippingAddress_RefID = (defaultShippingAddress != null) ? defaultShippingAddress.CMN_Address_RefID : Guid.Empty;
            office.Save(Connection, Transaction);

            #endregion

            return(returnValue);

            #endregion UserCode
        }
예제 #17
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_SD_1537 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            if (Parameter.CMN_BPT_BusinessParticipantID == Guid.Empty)
            {
                #region Create Mode

                #region BusinessParticipant


                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                bParticipant.IsNaturalPerson    = true;
                bParticipant.Tenant_RefID       = securityTicket.TenantID;
                bParticipant.Creation_Timestamp = DateTime.Now;
                bParticipant.Save(Connection, Transaction);

                #endregion

                #region Account

                ORM_USR_Account account = new ORM_USR_Account();

                account.Username    = Parameter.FirstName + "_" + Parameter.LastName;
                account.AccountType = 3;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID       = securityTicket.TenantID;
                account.Creation_Timestamp = DateTime.Now;
                account.Save(Connection, Transaction);

                P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505();
                codeParam.codeLength = 8;
                var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result;

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                accountCode.Account_RefID                   = account.USR_AccountID;
                accountCode.AccountCode_Value               = checkCodeValue.CodeValue;
                accountCode.AccountCode_ValidFrom           = DateTime.Now;
                accountCode.AccountCode_CurrentStatus_RefID = Guid.NewGuid();
                accountCode.IsAccountCode_Expirable         = false;
                accountCode.Tenant_RefID       = securityTicket.TenantID;
                accountCode.Creation_Timestamp = DateTime.Now;
                accountCode.Save(Connection, Transaction);

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID = accountCode.AccountCode_CurrentStatus_RefID;
                Device_AccountCode_StatusHistory.IsAccountCode_Active     = true;
                Device_AccountCode_StatusHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_StatusHistory.Tenant_RefID             = securityTicket.TenantID;
                Device_AccountCode_StatusHistory.Creation_Timestamp       = DateTime.Now;
                Device_AccountCode_StatusHistory.Save(Connection, Transaction);


                ORM_USR_Device_AccountCode_UsageHistory USR_Device_AccountCode_UsageHistory = new ORM_USR_Device_AccountCode_UsageHistory();
                USR_Device_AccountCode_UsageHistory.USR_Device_AccountCode_UsageHistoryID = Guid.NewGuid();
                USR_Device_AccountCode_UsageHistory.Tenant_RefID             = securityTicket.TenantID;
                USR_Device_AccountCode_UsageHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                USR_Device_AccountCode_UsageHistory.Creation_Timestamp       = DateTime.Now;
                USR_Device_AccountCode_UsageHistory.Save(Connection, Transaction);


                #endregion

                #region PersonInfo and Adresses

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Salutation_General   = Parameter.Salutation_General;
                personInfo.FirstName            = Parameter.FirstName;
                personInfo.LastName             = Parameter.LastName;
                personInfo.PrimaryEmail         = Parameter.PrimaryMail;
                personInfo.Address_RefID        = Guid.NewGuid();
                personInfo.Tenant_RefID         = securityTicket.TenantID;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_PER_PersonInfo_2_Address personAdress = new ORM_CMN_PER_PersonInfo_2_Address();
                personAdress.AssignmentID             = Guid.NewGuid();
                personAdress.CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                personAdress.CMN_Address_RefID        = personInfo.Address_RefID;
                personAdress.IsPrimary    = true;
                personAdress.Tenant_RefID = securityTicket.TenantID;
                personAdress.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.CMN_AddressID   = personInfo.Address_RefID;
                adress.City_Name       = Parameter.City_Name;
                adress.Province_Name   = Parameter.Province_Name;
                adress.Street_Name     = Parameter.Street_Name;
                adress.Street_Number   = Parameter.Street_Number;
                adress.City_PostalCode = Parameter.City_PostalCode;
                adress.Tenant_RefID    = securityTicket.TenantID;
                adress.Save(Connection, Transaction);

                #endregion

                #region Contacts

                foreach (var parContact in Parameter.Contacts)
                {
                    ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                    contact.Content          = parContact.Content;
                    contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Tenant_RefID     = securityTicket.TenantID;
                    contact.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    contact.Save(Connection, Transaction);
                }

                #endregion

                #region Driver To Employer

                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant bpt_asBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                bpt_asBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                bpt_asBP.BusinessParticipant_RefID          = bParticipant.CMN_BPT_BusinessParticipantID;
                bpt_asBP.AssociatedParticipant_FunctionName = "Driver";
                bpt_asBP.Tenant_RefID = securityTicket.TenantID;
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);

                #endregion

                #endregion
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);

                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                personInfo.Salutation_General = Parameter.Salutation_General;
                personInfo.FirstName          = Parameter.FirstName;
                personInfo.LastName           = Parameter.LastName;
                personInfo.PrimaryEmail       = Parameter.PrimaryMail;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.Load(Connection, Transaction, personInfo.Address_RefID);
                adress.City_Name     = Parameter.City_Name;
                adress.Province_Name = Parameter.Province_Name;
                adress.Street_Name   = Parameter.Street_Name;
                adress.Street_Number = Parameter.Street_Number;
                adress.Save(Connection, Transaction);

                foreach (var parContact in Parameter.Contacts)
                {
                    var query = new ORM_CMN_PER_CommunicationContact.Query();
                    query.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    query.IsDeleted        = false;
                    query.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                    var contact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query).First();
                    contact.Content      = parContact.Content;
                    contact.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Save(Connection, Transaction);
                }

                var associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associationQuery.BusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID;
                associationQuery.IsDeleted = false;

                var bpt_asBP = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery).First();
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);
            }
            return(returnValue);

            #endregion UserCode
        }
예제 #18
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_SUS_1346 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var adress        = new ORM_CMN_Address();
            var person2Adress = new ORM_CMN_PER_PersonInfo_2_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = adress.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || adress.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                person2Adress.CMN_Address_RefID = Parameter.CMN_AddressID;
            }

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

            if (Parameter.IsDeleted == true)
            {
                adress.IsDeleted        = true;
                person2Adress.IsDeleted = true;
                person2Adress.Save(Connection, Transaction);
                return(new FR_Guid(adress.Save(Connection, Transaction), adress.CMN_AddressID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.CMN_AddressID == Guid.Empty)
            {
                person2Adress.CMN_Address_RefID = adress.CMN_AddressID;
                person2Adress.Tenant_RefID      = securityTicket.TenantID;
                adress.Tenant_RefID             = securityTicket.TenantID;
            }

            adress.Street_Name     = Parameter.Street_Name;
            adress.Street_Number   = Parameter.Street_Number;
            adress.City_Name       = Parameter.City_Name;
            adress.City_PostalCode = Parameter.City_PostalCode;
            adress.Country_Name    = Parameter.Country_Name;
            adress.Country_ISOCode = Parameter.Country_ISOCode;

            person2Adress.CMN_PER_PersonInfo_RefID = Parameter.CMN_PER_PersonInfo_RefID;
            person2Adress.IsAddress_Billing        = Parameter.IsAddress_Billing;
            person2Adress.IsAddress_Shipping       = Parameter.IsAddress_Shipping;
            person2Adress.AddressLabel             = Parameter.AddressName;
            person2Adress.IsPrimary = Parameter.IsPrimary;

            person2Adress.Save(Connection, Transaction);
            return(new FR_Guid(adress.Save(Connection, Transaction), adress.CMN_AddressID));

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

            Guid PurchasingPowerAmount_Current;
            Guid PurchasingPowerAmount_Forecast;
            Guid ResidentialRent_MinPrice;
            Guid ResidentialRent_AveragePrice;
            Guid ResidentialRent_MaxPrice;
            Guid NonResidentialRent_MinPrice;
            Guid NonResidentialRent_AveragePrice;
            Guid NonResidentialRent_MaxPrice;

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Region   = Parameter.City_Region;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.City_AdministrativeDistrict = Parameter.City_AdministrativeDistrict;
            address.City_Name       = Parameter.City_Name;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.Save(Connection, Transaction);

            //for purchasingPowerAmountCurrent
            ORM_CMN_Price price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_PurchasingPowerAmount_Current_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_PurchasingPowerAmount_Current_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            PurchasingPowerAmount_Current = price.CMN_PriceID;

            ORM_CMN_Price_Value.Query priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            List <ORM_CMN_Price_Value> prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            ORM_CMN_Price_Value priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_PurchasingPowerAmount_Current_RefIDValue;
            priceValue.Save(Connection, Transaction);


            //for RegionInformation_PurchasingPowerAmount_Forecast_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            PurchasingPowerAmount_Forecast = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_MinPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_MinPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_MinPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_MinPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_MinPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_AveragePrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_AveragePrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_AveragePrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_AveragePrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_AveragePrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_MaxPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_MaxPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_MaxPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_MaxPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_MaxPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_MinPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_MinPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_MinPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_MinPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_MinPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_AveragePrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_AveragePrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_MaxPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_MaxPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for regionInfo and region
            ORM_CMN_LOC_Region region = new ORM_CMN_LOC_Region();
            if (Parameter.RegionID != Guid.Empty)
            {
                var result = region.Load(Connection, Transaction, Parameter.RegionID);
                if (result.Status != FR_Status.Success || region.CMN_LOC_RegionID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            ORM_RES_LOC_RegionInformation.Query regionInfo = new ORM_RES_LOC_RegionInformation.Query();
            regionInfo.CMN_LOC_Region_RefID = region.CMN_LOC_RegionID;
            regionInfo.Tenant_RefID         = securityTicket.TenantID;
            regionInfo.IsDeleted            = false;
            List <ORM_RES_LOC_RegionInformation> infos = ORM_RES_LOC_RegionInformation.Query.Search(Connection, Transaction, regionInfo);

            ORM_RES_LOC_RegionInformation info;
            if (infos.Count > 0)
            {
                info = infos[0];
                info.RegionInformation_RegionArea_in_sqkm            = Parameter.RegionInformation_RegionArea_in_sqkm;
                info.RegionInformation_TotalPopulation               = Parameter.RegionInformation_TotalPopulation;
                info.RegionInformation_Population_per_sqkm           = Parameter.RegionInformation_Population_per_sqkm;
                info.RegionInformation_RegionUnemploymentRatePercent = Parameter.RegionInformation_RegionUnemploymentRatePercent;
                info.RegionInformation_NumberOfHouseholds_Current    = Parameter.RegionInformation_NumberOfHouseholds_Current;
                info.RegionInformation_NumberOfHouseholds_Forecast   = Parameter.RegionInformation_NumberOfHouseholds_Forecast;
                info.Tenant_RefID = securityTicket.TenantID;
                info.Save(Connection, Transaction);
            }
            else
            {
                info = new ORM_RES_LOC_RegionInformation();
                info.CMN_LOC_Region_RefID = region.CMN_LOC_RegionID;
                info.RegionInformation_RegionArea_in_sqkm                    = Parameter.RegionInformation_RegionArea_in_sqkm;
                info.RegionInformation_TotalPopulation                       = Parameter.RegionInformation_TotalPopulation;
                info.RegionInformation_Population_per_sqkm                   = Parameter.RegionInformation_Population_per_sqkm;
                info.RegionInformation_RegionUnemploymentRatePercent         = Parameter.RegionInformation_RegionUnemploymentRatePercent;
                info.RegionInformation_NumberOfHouseholds_Current            = Parameter.RegionInformation_NumberOfHouseholds_Current;
                info.RegionInformation_NumberOfHouseholds_Forecast           = Parameter.RegionInformation_NumberOfHouseholds_Forecast;
                info.RegionInformation_PurchasingPowerAmount_Current_RefID   = PurchasingPowerAmount_Current;
                info.RegionInformation_PurchasingPowerAmount_Forecast_RefID  = PurchasingPowerAmount_Forecast;
                info.RegionInformation_ResidentialRent_MinPrice_RefID        = ResidentialRent_MinPrice;
                info.RegionInformation_ResidentialRent_AveragePrice_RefID    = ResidentialRent_AveragePrice;
                info.RegionInformation_ResidentialRent_MaxPrice_RefID        = ResidentialRent_MaxPrice;
                info.RegionInformation_NonResidentialRent_MinPrice_RefID     = NonResidentialRent_MinPrice;
                info.RegionInformation_NonResidentialRent_AveragePrice_RefID = NonResidentialRent_AveragePrice;
                info.RegionInformation_NonResidentialRent_MaxPrice_RefID     = NonResidentialRent_MaxPrice;
                info.Tenant_RefID = securityTicket.TenantID;
                info.Save(Connection, Transaction);
            }

            //save region
            region.Country_RefID = Parameter.Country_RefID;
            region.Tenant_RefID  = securityTicket.TenantID;
            region.Save(Connection, Transaction);

            //for location
            ORM_CMN_LOC_Location location = new ORM_CMN_LOC_Location();
            if (Parameter.CMN_LOC_LocationID != Guid.Empty)
            {
                var result = location.Load(Connection, Transaction, Parameter.CMN_LOC_LocationID);
                if (result.Status != FR_Status.Success || location.CMN_LOC_LocationID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            location.Region_RefID  = region.CMN_LOC_RegionID;
            location.Address_RefID = address.CMN_AddressID;
            location.Tenant_RefID  = securityTicket.TenantID;
            location.Save(Connection, Transaction);

            //add location ref id in realesteProperty
            ORM_RES_RealestateProperty.Query realestatePropertyQuery = new ORM_RES_RealestateProperty.Query();
            realestatePropertyQuery.RES_RealestatePropertyID = Parameter.RealestatePropertyID;
            List <ORM_RES_RealestateProperty> realestates = ORM_RES_RealestateProperty.Query.Search(Connection, Transaction, realestatePropertyQuery);
            ORM_RES_RealestateProperty        realestate  = realestates[0];
            realestate.RealestateProperty_Location_RefID = location.CMN_LOC_LocationID;
            realestate.Save(Connection, Transaction);

            //for locationInformation
            ORM_RES_LOC_LocationInformation locationInformation = new ORM_RES_LOC_LocationInformation();
            if (Parameter.LocationInformationID != Guid.Empty)
            {
                var result = locationInformation.Load(Connection, Transaction, Parameter.LocationInformationID);
                if (result.Status != FR_Status.Success || locationInformation.RES_LOC_LocationInformationID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            locationInformation.CMN_LOC_Location_RefID                   = location.CMN_LOC_LocationID;
            locationInformation.LocationInformation_MapImage_DocID       = Parameter.MapImage;
            locationInformation.LocationInformation_SatelliteImage_DocID = Parameter.SateliteImage;
            locationInformation.LocationInformation_AddressImage_DocID   = Parameter.AddressImage;
            locationInformation.Tenant_RefID = securityTicket.TenantID;
            locationInformation.Save(Connection, Transaction);

            //for meansOfTrasnportation, emmissions, infrastructures...
            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation     transportation;
            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure infrastructure;
            ORM_RES_LOC_LocationInformation_2_Emmission           emmission;
            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality qualitie;
            ORM_RES_LOC_LocationInfo_2_ParkingSituation           parkingSituation;
            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy         residentialVacancy;
            ORM_RES_LOC_LocationInfo_2_CommercialVacancy          commercialVacancy;

            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query transportationQuery = new ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query();
            transportationQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            transportationQuery.Tenant_RefID = securityTicket.TenantID;
            transportationQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query.SoftDelete(Connection, Transaction, transportationQuery);

            if (Parameter.RES_LOC_MeansOfTransportation_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_MeansOfTransportation_RefID)
                {
                    transportation = new ORM_RES_LOC_LocationInformation_2_MeansOfTransportation();
                    transportation.RES_LOC_LocationInformation_RefID   = locationInformation.RES_LOC_LocationInformationID;
                    transportation.RES_LOC_MeansOfTransportation_RefID = guid;
                    transportation.Tenant_RefID = securityTicket.TenantID;
                    transportation.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query infrastructureQuery = new ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query();
            infrastructureQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            infrastructureQuery.Tenant_RefID = securityTicket.TenantID;
            infrastructureQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query.SoftDelete(Connection, Transaction, infrastructureQuery);

            if (Parameter.RES_LOC_SurroundingInfrastructure_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_SurroundingInfrastructure_RefID)
                {
                    infrastructure = new ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure();
                    infrastructure.RES_LOC_LocationInformation_RefID       = locationInformation.RES_LOC_LocationInformationID;
                    infrastructure.RES_LOC_SurroundingInfrastructure_RefID = guid;
                    infrastructure.Tenant_RefID = securityTicket.TenantID;
                    infrastructure.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_Emmission.Query emmissionQuery = new ORM_RES_LOC_LocationInformation_2_Emmission.Query();
            emmissionQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            emmissionQuery.Tenant_RefID = securityTicket.TenantID;
            emmissionQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_Emmission.Query.SoftDelete(Connection, Transaction, emmissionQuery);

            if (Parameter.RES_LOC_Emmission_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_Emmission_RefID)
                {
                    emmission = new ORM_RES_LOC_LocationInformation_2_Emmission();
                    emmission.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
                    emmission.RES_LOC_Emmission_RefID           = guid;
                    emmission.Tenant_RefID = securityTicket.TenantID;
                    emmission.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query neighborhoodQuery = new ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query();
            neighborhoodQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            neighborhoodQuery.Tenant_RefID = securityTicket.TenantID;
            neighborhoodQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query.SoftDelete(Connection, Transaction, neighborhoodQuery);

            if (Parameter.RES_LOC_NeighborhoodQuality_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_NeighborhoodQuality_RefID)
                {
                    qualitie = new ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality();
                    qualitie.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
                    qualitie.RES_LOC_NeighborhoodQuality_RefID = guid;
                    qualitie.Tenant_RefID = securityTicket.TenantID;
                    qualitie.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query parkingQuery = new ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query();
            parkingQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            parkingQuery.Tenant_RefID = securityTicket.TenantID;
            parkingQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query.SoftDelete(Connection, Transaction, parkingQuery);

            if (Parameter.RES_LOC_ParkingSituation_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_ParkingSituation_RefID)
                {
                    parkingSituation = new ORM_RES_LOC_LocationInfo_2_ParkingSituation();
                    parkingSituation.RES_LOC_LocationInfo_RefID     = locationInformation.RES_LOC_LocationInformationID;
                    parkingSituation.RES_LOC_ParkingSituation_RefID = guid;
                    parkingSituation.Tenant_RefID = securityTicket.TenantID;
                    parkingSituation.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query residentalQuery = new ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query();
            residentalQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            residentalQuery.Tenant_RefID = securityTicket.TenantID;
            residentalQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query.SoftDelete(Connection, Transaction, residentalQuery);

            if (Parameter.RES_LOC_ResidentialVacancies_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_ResidentialVacancies_RefID)
                {
                    residentialVacancy = new ORM_RES_LOC_LocationInfo_2_ResidentialVacancy();
                    residentialVacancy.RES_LOC_LocationInfo_RefID       = locationInformation.RES_LOC_LocationInformationID;
                    residentialVacancy.RES_LOC_ResidentialVacancy_RefID = guid;
                    residentialVacancy.Tenant_RefID = securityTicket.TenantID;
                    residentialVacancy.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query commercialQuery = new ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query();
            commercialQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            commercialQuery.Tenant_RefID = securityTicket.TenantID;
            commercialQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query.SoftDelete(Connection, Transaction, commercialQuery);

            if (Parameter.RES_LOC_CommercialVacancies_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_CommercialVacancies_RefID)
                {
                    commercialVacancy = new ORM_RES_LOC_LocationInfo_2_CommercialVacancy();
                    commercialVacancy.RES_LOC_LocationInfo_RefID      = locationInformation.RES_LOC_LocationInformationID;
                    commercialVacancy.RES_LOC_CommercialVacancy_RefID = guid;
                    commercialVacancy.Tenant_RefID = securityTicket.TenantID;
                    commercialVacancy.Save(Connection, Transaction);
                }
            }

            returnValue.Result = location.CMN_LOC_LocationID;

            return(returnValue);

            #endregion UserCode
        }