Example #1
0
        /// <inheritdoc />
        public async Task <DBRPGGroup> RemoveMemberAsync(int characterId, CancellationToken token = default)
        {
            //If there is only one member then we should disband the group
            //But we NEED TO KNOW that the group was disbanded for future proof realtime social notifications
            //involving group listing and possibily other stuff.
            var groupMember = await Context.Set <DBRPGGroupMember>()
                              .Include(gm => gm.Group)
                              .ThenInclude(g => g.Members)
                              .FirstAsync(gm => gm.CharacterId == characterId, token);

            groupMember.Group
            .Members
            .Remove(groupMember);

            //Group is empty, let's disband it.
            if (!groupMember.Group.Members.Any())
            {
                ModelSet.Remove(groupMember.Group);
            }

            await Context.SaveChangesAsync(true, token);

            //Caller will be able to see group state now, especially helpful if the group is empty or disbanded.
            return(groupMember.Group);
        }
        /// <inheritdoc />
        public async Task <bool> TryDeleteAsync(TKey key, CancellationToken token = default)
        {
            //If it doesn't exist then this will just fail, so get out soon.
            if (!await ContainsAsync(key, token))
            {
                return(false);
            }

            TModelType modelType = await RetrieveAsync(key, token);

            ModelSet.Remove(modelType);

            return(await SaveAndCheckResultsAsync(token));
        }
Example #3
0
        /// <inheritdoc />
        public async Task <bool> TryDeleteAsync(TKey key)
        {
            //If it doesn't exist then this will just fail, so get out soon.
            if (!await ContainsAsync(key).ConfigureAwaitFalse())
            {
                return(false);
            }

            TModelType modelType = await RetrieveAsync(key)
                                   .ConfigureAwaitFalse();

            ModelSet.Remove(modelType);

            return(await SaveAndCheckResultsAsync()
                   .ConfigureAwaitFalse());
        }