Example #1
0
        // MEMBERS
        public async Task <Organization> AddPlayerAsync(User requester, string organizationId, string id)
        {
            List <SanityOrganization> organizations = await GetOrganizationsAsync();

            Player player = (await GetPlayersAsync()).FirstOrDefault(p => p.Id == id || p.DiscordId == id);

            SanityOrganization organization = organizations.FirstOrDefault(o => o.Id == organizationId);

            if (organization == null)
            {
                throw new Exception("Organization not found");
            }

            SanityPendingMember pending = organization.Pending.FirstOrDefault(p => p.Player.Ref == player.Id);

            if (pending != null)
            {
                organization.Pending.Remove(pending);
            }

            organization.Members.Add(new SanityMember(player, "member"));

            await Sanity.DocumentSet <SanityOrganization>().Update(organization).CommitAsync();

            return(organization.ToOrganization());
        }
Example #2
0
        public async Task <Organization> RemovePendingPlayerAsync(User requester, string organizationId, string playerId)
        {
            SanityOrganization organization = (await GetOrganizationsAsync()).FirstOrDefault(o => o.Id == organizationId && o.HasEditAccess(requester));

            if (organization == null)
            {
                throw new Exception();
            }

            SanityPendingMember member = organization.Pending.Find(m => m.Player.Ref == playerId);

            if (member == null)
            {
                throw new Exception();
            }

            organization.Members.Add(new SanityMember(member.Player.Value, "member"));

            organization.Pending.Remove(member);

            await Sanity.DocumentSet <SanityOrganization>().Update(organization).CommitAsync();

            return(organization.ToOrganization());
        }