예제 #1
0
 public PartyCongressCandidatesListViewModel(List <CongressCandidate> candidates, IPartyService partyService, Entities.Party party)
     : base(candidates)
 {
     PartyRole = PartyRoleEnum.NotAMember;
     if (SessionHelper.CurrentEntity.Citizen != null)
     {
         PartyRole = partyService.GetPartyRole(SessionHelper.LoggedCitizen, party);
         if (partyService.CanAcceptCongressCandidates(SessionHelper.CurrentEntity.Citizen, party))
         {
             CanAcceptCandidates = true;
         }
     }
 }
예제 #2
0
        public void AddMember(Citizen citizen, PartyRoleEnum partyRole)
        {
            PartyMember member = new PartyMember()
            {
                Citizen     = citizen,
                CitizenID   = citizen.ID,
                Party       = party,
                PartyID     = party.ID,
                PartyRoleID = (int)partyRole
            };

            party.PartyMembers.Add(member);

            citizen.PartyMember = member;
        }
예제 #3
0
        public static string ToHumanReadable(this PartyRoleEnum partyRole)
        {
            switch (partyRole)
            {
            case PartyRoleEnum.Manager:
                return("manager");

            case PartyRoleEnum.Member:
                return("member");

            case PartyRoleEnum.President:
                return("president");

            case PartyRoleEnum.NotAMember:
                return("not a member");
            }
            throw new NotImplementedException();
        }
예제 #4
0
        public MethodResult CanSeeJoinRequests(Citizen citizen, Party party)
        {
            if (party == null)
            {
                return(new MethodResult("Party does not exist!"));
            }

            PartyRoleEnum role = GetPartyRole(citizen, party);

            if (role == PartyRoleEnum.NotAMember)
            {
                return(new MethodResult("You are not a member of the party!"));
            }
            if (party.GetJoinMethod() != JoinMethodEnum.Request)
            {
                return(new MethodResult("Party does not accept requests!"));
            }
            if (role <= PartyRoleEnum.Manager)
            {
                return(new MethodResult("You must be at least manager to view join requests!"));
            }

            return(MethodResult.Success);
        }
예제 #5
0
        public PartyInfoViewModel(Entities.Party party)
        {
            var citizen = SessionHelper.LoggedCitizen;
            var entity  = SessionHelper.CurrentEntity;

            var           isActingAsParty = entity.EntityID == party.ID;
            PartyRoleEnum userPartyRole   = PartyRoleEnum.NotAMember;

            if (citizen.PartyMember != null && citizen.PartyMember.PartyID == party.ID)
            {
                userPartyRole = (PartyRoleEnum)citizen.PartyMember.PartyRoleID;
            }

            PartyAvatar     = new ImageViewModel(party.Entity.ImgUrl);
            PartyName       = party.Entity.Name;
            PartyCountry    = party.Country.Entity.Name;
            JoinMethod      = (JoinMethodEnum)party.JoinMethodID;
            PartyRole       = userPartyRole;
            PartyID         = party.ID;
            IsActingAsParty = isActingAsParty;

            MemberCount      = party.PartyMembers.Count;
            CongressmenCount = party.PartyMembers.Where(pm => pm.Citizen.Congressmen.Any(c => c.CountryID == party.CountryID)).Count();

            if (entity.GetEntityType() == EntityTypeEnum.Citizen && PartyRole == PartyRoleEnum.NotAMember)
            {
                var partyService = DependencyResolver.Current.GetService <IPartyService>();
                if (party.JoinMethodID == (int)JoinMethodEnum.Invite)
                {
                    var invite = citizen
                                 .PartyInvites.FirstOrDefault(i => i.PartyID == party.ID);
                    if (invite != null)
                    {
                        CanAcceptJoinOffer = true;
                        InviteID           = invite.ID;
                    }
                }
                else if (party.JoinMethodID == (int)JoinMethodEnum.Request)
                {
                    var request = citizen.PartyJoinRequests.FirstOrDefault(i => i.PartyID == party.ID);
                    if (request != null)
                    {
                        HasSendJoinRequest = true;
                        RequestID          = request.ID;
                    }
                    else if (partyService.CanSendJoinRequest(citizen, party, message: "").isSuccess)
                    {
                        CanSendJoinRequest = true;
                    }
                }
            }

            if (PartyRole >= PartyRoleEnum.Manager)
            {
                AvatarChange = new AvatarChangeViewModel(party.ID);
            }

            CanSeeInvites  = JoinMethod == JoinMethodEnum.Invite && PartyRole >= PartyRoleEnum.Manager;
            CanSeeRequests = JoinMethod == JoinMethodEnum.Request && PartyRole >= PartyRoleEnum.Manager;

            createMenu();
        }
예제 #6
0
 public static bool Is(this PartyMember partyMember, PartyRoleEnum partyRole)
 {
     return(partyMember.PartyRoleID == (int)partyRole);
 }