protected static FR_L5MC_MJGR_1414 Execute(DbConnection Connection, DbTransaction Transaction, P_L5MC_MJGR_1414 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5MC_MJGR_1414();
            returnValue.Result = new L5MC_MJGR_1414();

            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 role = ORM_HEC_CMT_OfferedRole.Query.Search(Connection, Transaction, new ORM_HEC_CMT_OfferedRole.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECommunityRole.Contributor),
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            }).Single();

            var prevRequest = ORM_HEC_CMT_GroupSubscription_Request.Query.Search(Connection, Transaction, new ORM_HEC_CMT_GroupSubscription_Request.Query()
            {
                Tenant_RefID         = securityTicket.TenantID,
                IsDeleted            = false,
                IsApproved           = false,
                IsRequested          = false,
                Membership_RefID     = Parameter.HEC_CMT_MembershipID,
                CommunityGroup_RefID = Parameter.HEC_CMT_CommunityGroupID
            }).SingleOrDefault();

            var subscription = ORM_HEC_CMT_GroupSubscription.Query.Search(Connection, Transaction, new ORM_HEC_CMT_GroupSubscription.Query()
            {
                Tenant_RefID         = securityTicket.TenantID,
                IsDeleted            = false,
                Membership_RefID     = Parameter.HEC_CMT_MembershipID,
                CommunityGroup_RefID = Parameter.HEC_CMT_CommunityGroupID
            }).SingleOrDefault();

            if (subscription == null && prevRequest == null)
            {
                var request = new ORM_HEC_CMT_GroupSubscription_Request()
                {
                    HEC_CMT_GroupSubscription_RequestID = Guid.NewGuid(),
                    Tenant_RefID         = securityTicket.TenantID,
                    Membership_RefID     = Parameter.HEC_CMT_MembershipID,
                    CommunityGroup_RefID = Parameter.HEC_CMT_CommunityGroupID,
                    IsRequested          = true
                };
                request.Save(Connection, Transaction);

                var roleRequest = new ORM_HEC_CMT_OfferedRoles_2_GroupSubscriptionRequest()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    AssignmentID = Guid.NewGuid(),
                    HEC_CMT_OfferedRole_RefID = role.HEC_CMT_OfferedRoleID,
                    HEC_CMT_GroupSubscription_Request_RefID = request.HEC_CMT_GroupSubscription_RequestID
                };
                roleRequest.Save(Connection, Transaction);

                returnValue.Result.IsSuccess = true;
                returnValue.Result.HEC_CMT_GroupSubscription_RequestID = request.HEC_CMT_GroupSubscription_RequestID;
            }
            else
            {
                returnValue.Result.FailReason = new L5MC_MJGR_1414_FailReason()
                {
                    IfAlreadyGorupMember_GroupID = subscription == null ? Guid.Empty : subscription.HEC_CMT_GroupSubscriptionID,
                    IsAlreadyGorupMember         = subscription != null,
                    IsAlreadyRequested           = prevRequest != null,
                    IfAlreadyRequested_RequestID = prevRequest == null ? Guid.Empty : prevRequest.HEC_CMT_GroupSubscription_RequestID
                };
            }

            return(returnValue);

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

            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 role = ORM_HEC_CMT_OfferedRole.Query.Search(Connection, Transaction, new ORM_HEC_CMT_OfferedRole.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECommunityRole.Consumer),
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            }).Single();


            var memberRequests = cls_Get_Requests_for_GroupID_and_MemberID.Invoke(Connection, Transaction, new P_L5AC_GRfGaMs_1449()
            {
                GroupID = Parameter.HEC_CMT_CommunityGroupID, MemberID = Parameter.HEC_CMT_MembershipID
            }, securityTicket).Result;
            var memberRoles = cls_Get_MemberRoles_for_GroupID.Invoke(Connection, Transaction, new P_L5MC_GMRfGMID_1505()
            {
                GroupID = Parameter.HEC_CMT_CommunityGroupID, MemberID = Parameter.HEC_CMT_MembershipID
            }, securityTicket).Result.Roles;

            var subscription = ORM_HEC_CMT_GroupSubscription.Query.Search(Connection, Transaction, new ORM_HEC_CMT_GroupSubscription.Query()
            {
                Tenant_RefID         = securityTicket.TenantID,
                IsDeleted            = false,
                Membership_RefID     = Parameter.HEC_CMT_MembershipID,
                CommunityGroup_RefID = Parameter.HEC_CMT_CommunityGroupID
            }).SingleOrDefault();

            var prevRequestStillActive = memberRequests.Where(w => w.Role_GlobalPropertyMatchingID == EnumUtils.GetEnumDescription(ECommunityRole.Consumer)).Count() > 0;
            var isThereCutomerRole     = memberRoles.Where(w => w.GlobalPropertyMatchingID == EnumUtils.GetEnumDescription(ECommunityRole.Consumer)).Count() > 0;
            if (subscription == null || prevRequestStillActive && isThereCutomerRole)
            {
                returnValue.Result.IsSuccess  = false;
                returnValue.Result.FailReason = new L5MC_MCRR_1440_FailReason()
                {
                    IsntGroupMember              = true,
                    IsAlreadyHaveThisRole        = isThereCutomerRole,
                    IsAlreadyRequested           = prevRequestStillActive,
                    IfAlreadyRequested_RequestID = isThereCutomerRole ? memberRequests.First(w => w.Role_GlobalPropertyMatchingID == EnumUtils.GetEnumDescription(ECommunityRole.Consumer)).HEC_CMT_GroupSubscription_RequestID : Guid.Empty
                };
            }
            else
            {
                var request = new ORM_HEC_CMT_GroupSubscription_Request()
                {
                    HEC_CMT_GroupSubscription_RequestID = Guid.NewGuid(),
                    Tenant_RefID         = securityTicket.TenantID,
                    Membership_RefID     = Parameter.HEC_CMT_MembershipID,
                    CommunityGroup_RefID = Parameter.HEC_CMT_CommunityGroupID,
                    IsRequested          = true
                };
                request.Save(Connection, Transaction);

                var roleRequest = new ORM_HEC_CMT_OfferedRoles_2_GroupSubscriptionRequest()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    AssignmentID = Guid.NewGuid(),
                    HEC_CMT_OfferedRole_RefID = role.HEC_CMT_OfferedRoleID,
                    HEC_CMT_GroupSubscription_Request_RefID = request.HEC_CMT_GroupSubscription_RequestID
                };
                roleRequest.Save(Connection, Transaction);

                returnValue.Result.IsSuccess = true;
                returnValue.Result.HEC_CMT_GroupSubscription_RequestID = request.HEC_CMT_GroupSubscription_RequestID;
            }

            return(returnValue);

            #endregion UserCode
        }