示例#1
0
        public void RevokeInvite(ClanMembership clanMemberShip, string personWhoInvitesBattleTag)
        {
            if (ChiefTain != personWhoInvitesBattleTag && !Shamans.Contains(personWhoInvitesBattleTag))
            {
                throw new ValidationException("Only chieftains and shamans can invite");
            }

            clanMemberShip.RevokeInvite();

            PendingInvites.Remove(clanMemberShip.BattleTag);
        }
示例#2
0
        public static Clan Create(string clanName, string clanAbbrevation, ClanMembership founder)
        {
            if (!(founder.ClanId == null || string.IsNullOrWhiteSpace(founder.ClanId)))
            {
                throw new ValidationException("Founder can not be in another clan");
            }

            var clan = new Clan
            {
                ClanName  = clanName,
                ClanState = new NotFoundedClan(founder.BattleTag),
                ClanId    = clanAbbrevation,
            };

            return(clan);
        }
示例#3
0
        public void AcceptInvite(ClanMembership membership)
        {
            if (Members.Contains(membership.BattleTag))
            {
                throw new ValidationException("Can not participate in clan twice");
            }
            if (!PendingInvites.Contains(membership.BattleTag))
            {
                throw new ValidationException("Player was not invites to sign the clan");
            }

            membership.JoinClan(this);

            ClanState = ClanState.AcceptInvite(membership);

            PendingInvites.Remove(membership.BattleTag);
        }
        public async Task InviteToClan(string battleTag, string clanId, string personWhoInvitesBattleTag)
        {
            var clanMemberShip = await _clanRepository.LoadMemberShip(battleTag)
                                 ?? ClanMembership.Create(battleTag);

            var clan = await _clanRepository.LoadClan(clanId);

            if (clan == null)
            {
                throw new ValidationException("Clan not found");
            }

            clan.Invite(clanMemberShip, personWhoInvitesBattleTag);

            await _clanRepository.UpsertClan(clan);

            await _clanRepository.UpsertMemberShip(clanMemberShip);
        }
示例#5
0
        public void KickPlayer(ClanMembership clanMemberShip, string actingPlayer)
        {
            if (ChiefTain != actingPlayer && !Shamans.Contains(actingPlayer))
            {
                throw new ValidationException("Only Chieftain or shamans can kick players");
            }
            if (!Members.Contains(clanMemberShip.BattleTag) && !Shamans.Contains(clanMemberShip.BattleTag))
            {
                throw new ValidationException("Player not in this clan");
            }
            if (clanMemberShip.BattleTag == ChiefTain)
            {
                throw new ValidationException("Can not kick chieftain");
            }

            clanMemberShip.LeaveClan();
            Members.Remove(clanMemberShip.BattleTag);
            Shamans.Remove(clanMemberShip.BattleTag);
        }
示例#6
0
        public void LeaveClan(ClanMembership clanMemberShip)
        {
            if (clanMemberShip.BattleTag == ChiefTain)
            {
                throw new ValidationException("Chieftain can not leave clan, transfer ownership first");
            }
            clanMemberShip.LeaveClan();

            ClanState = ClanState.LeaveClan(clanMemberShip);

            if (!IsSuccesfullyFounded)
            {
                FoundingFathers.Remove(clanMemberShip.BattleTag);
            }
            else
            {
                Members.Remove(clanMemberShip.BattleTag);
            }
        }
示例#7
0
        public void Invite(ClanMembership clanMemberShip, string personWhoInvitesBattleTag)
        {
            if (ChiefTain != personWhoInvitesBattleTag && !Shamans.Contains(personWhoInvitesBattleTag))
            {
                throw new ValidationException("Only chieftains and shamans can invite");
            }
            if (PendingInvites.Contains(clanMemberShip.BattleTag))
            {
                throw new ValidationException("Can not invite player twice");
            }
            if (Members.Contains(clanMemberShip.BattleTag))
            {
                throw new ValidationException("Can not invite player twice");
            }
            if (FoundingFathers.Contains(clanMemberShip.BattleTag))
            {
                throw new ValidationException("Can not invite player twice");
            }

            clanMemberShip.Invite(this);

            PendingInvites.Add(clanMemberShip.BattleTag);
        }
示例#8
0
 public Task UpsertMemberShip(ClanMembership clanMemberShip)
 {
     return(UpsertTimed(clanMemberShip, c => c.BattleTag == clanMemberShip.BattleTag));
 }
示例#9
0
        public void RejectInvite(ClanMembership clanMemberShip)
        {
            clanMemberShip.RevokeInvite();

            PendingInvites.Remove(clanMemberShip.BattleTag);
        }
        public async Task <Clan> AcceptInvite(string playerBattleTag, string clanId)
        {
            var clan = await _clanRepository.LoadClan(clanId);

            var clanMemberShip = await _clanRepository.LoadMemberShip(playerBattleTag) ?? ClanMembership.Create(playerBattleTag);

            clan.AcceptInvite(clanMemberShip);
            await _clanRepository.UpsertClan(clan);

            await _clanRepository.UpsertMemberShip(clanMemberShip);

            return(clan);
        }
        public async Task <Clan> CreateClan(string clanName, string clanAbbrevation, string battleTagOfFounder)
        {
            var memberShip = await _clanRepository.LoadMemberShip(battleTagOfFounder) ?? ClanMembership.Create(battleTagOfFounder);

            var clan     = Clan.Create(clanName, clanAbbrevation, memberShip);
            var wasSaved = await _clanRepository.TryInsertClan(clan);

            if (!wasSaved)
            {
                throw new ValidationException("Clan Name allready taken");
            }
            memberShip.ClanId   = clan.ClanId;
            memberShip.ClanName = clan.ClanName;
            await _clanRepository.UpsertMemberShip(memberShip);

            return(clan);
        }