protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5MPC_SMC_1101 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); returnValue.Result = new Guid(); #region Save var community = ORM_HEC_CMT_Community.Query.Search(Connection, Transaction, new ORM_HEC_CMT_Community.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, IsCommunityOperatedByThisTenant = true }).Single(); var membershipType = ORM_HEC_CMT_Community_OfferedMembershipType.Query.Search(Connection, Transaction, new ORM_HEC_CMT_Community_OfferedMembershipType.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, IsAvailableFor_Tenants = Parameter.IsTenant, IsAvailableFor_Doctors = !Parameter.IsTenant }).Single(); var members = ORM_HEC_CMT_Membership.Query.Search(Connection, Transaction, new ORM_HEC_CMT_Membership.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, BusinessParticipant_RefID = Parameter.BusinessParticipantID }).SingleOrDefault(); if (members == null) { members = new ORM_HEC_CMT_Membership() { HEC_CMT_MembershipID = Guid.NewGuid(), Tenant_RefID = securityTicket.TenantID, CommunityMembershipITL = Guid.Empty.ToString(), BusinessParticipant_RefID = Parameter.BusinessParticipantID, Community_RefID = community.HEC_CMT_CommunityID }; members.Save(Connection, Transaction); } var creds = ORM_HEC_CMT_Membership_Credential.Query.Search(Connection, Transaction, new ORM_HEC_CMT_Membership_Credential.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, Membership_RefID = members.HEC_CMT_MembershipID }).SingleOrDefault(); if (creds == null) { creds = new ORM_HEC_CMT_Membership_Credential() { HEC_CMT_Membership_CredentialID = Guid.NewGuid(), Tenant_RefID = securityTicket.TenantID, Membership_RefID = members.HEC_CMT_MembershipID, }; } creds.Membership_Password = Parameter.Membership_Password; creds.Membership_Username = Parameter.Membership_Username; creds.Save(Connection, Transaction); if (!Parameter.IsTenant) { var group = ORM_HEC_CMT_CommunityGroup.Query.Search(Connection, Transaction, new ORM_HEC_CMT_CommunityGroup.Query() { Tenant_RefID = securityTicket.TenantID, IsPrivate = false, IsDeleted = false, CommunityGroupCode = "FAVORITES" }).Single(); var m2g = ORM_HEC_CMT_GroupSubscription.Query.Search(Connection, Transaction, new ORM_HEC_CMT_GroupSubscription.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, Membership_RefID = members.HEC_CMT_MembershipID, CommunityGroup_RefID = group.HEC_CMT_CommunityGroupID }).SingleOrDefault(); if (m2g == null) { m2g = new ORM_HEC_CMT_GroupSubscription() { Tenant_RefID = securityTicket.TenantID, Membership_RefID = members.HEC_CMT_MembershipID, CommunityGroup_RefID = group.HEC_CMT_CommunityGroupID }; m2g.Save(Connection, Transaction); } } #endregion return(returnValue); #endregion UserCode }