Beispiel #1
0
 public PersonRole AddRole(RoleType roleType, int organizationId, int geographyId)
 {
     return(PersonRole.Create(Identity, roleType, organizationId, geographyId));
 }
Beispiel #2
0
        //public void Terminate ()
        //{
        //    Terminate(EventSource.Unknown);
        //}


        public void Terminate(EventSource eventSource, Person actingPerson, string description)
        {
            if (base.Active)
            {
                //Added removal of Roles here to make SURE they always are removed with the membership.
                Authority authority = Person.GetAuthority();

                int actingPersonId = actingPerson == null ? 0 : actingPerson.Identity;

                BasicPersonRole[] roles    = authority.AllPersonRoles;
                List <PersonRole> theRoles = new List <PersonRole>();

                foreach (BasicPersonRole basicRole in roles)
                {
                    PersonRole personRole = PersonRole.FromBasic(basicRole);
                    theRoles.Add(personRole);
                    if (personRole.OrganizationId == OrganizationId)
                    {
                        PWEvents.CreateEvent(eventSource, EventType.DeletedRole, actingPersonId,
                                             personRole.OrganizationId, personRole.GeographyId,
                                             Person.Identity, (int)personRole.Type,
                                             string.Empty);
                        PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.RoleDeleted,
                                    "Role " + personRole.Type + " of " + personRole.Geography.Name +
                                    " was deleted with membership.", string.Empty);
                        personRole.Delete();
                    }
                }

                //now check if this means that you no longer are a member of some uplevel org, then remove those roles as well
                foreach (PersonRole personRole in theRoles)
                {
                    if (!Person.MemberOfWithInherited(personRole.Organization))
                    {
                        PWEvents.CreateEvent(eventSource, EventType.DeletedRole, actingPersonId,
                                             personRole.OrganizationId, personRole.GeographyId,
                                             Person.Identity, (int)personRole.Type,
                                             string.Empty);
                        PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.RoleDeleted,
                                    "Role " + personRole.Type + " of " + personRole.Geography.Name +
                                    " was deleted with membership of all suborgs.", string.Empty);
                        personRole.Delete();
                    }
                }

                EventSource src = EventSource.PirateWeb;
                try
                {
                    if (HttpContext.Current == null)
                    {
                        src = EventSource.PirateBot;
                    }
                }
                catch
                {
                    src = EventSource.PirateBot;
                }


                PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.MemberLost,
                            eventSource + ":" + description, string.Empty);
                PWEvents.CreateEvent(src, EventType.LostMember, actingPersonId, OrganizationId, Person.GeographyId,
                                     Person.Identity, 0, OrganizationId.ToString());


                //Added LogChurn here to make SURE they always are logged with the membership.
                if (PersonId > 0 && OrganizationId > 0 && base.Expires != new DateTime(1900, 1, 1))
                {
                    ChurnData.LogChurn(PersonId, OrganizationId);
                }
                SwarmDb.GetDatabaseForWriting().TerminateMembership(Identity);
                base.Active         = false;
                base.DateTerminated = DateTime.Now;

                // Remove all newsletter subscriptions once the membership is terminated (to make sure default is now off and only turn off explicitly turned-on subscriptions)

                // HACK HACK HACK: uses feed IDs in an extremely ugly way to loop 1-9. Should use NewsletterFeeds.ForOrganization() once support for newsletters in different orgs are established.

                for (int newsletterFeedId = 1; newsletterFeedId < 10; newsletterFeedId++)
                {
                    try
                    {
                        if (this.person.IsSubscribing(newsletterFeedId))
                        {
                            this.person.SetSubscription(newsletterFeedId, false);
                        }
                    }
                    catch (Exception)
                    {
                        // ignore nonexisting newsletter feeds -- this is a hack anyway
                    }
                }
            }
        }