public static async Task <TicTacToeSharedGroupData> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req,
            ILogger log)
        {
            var context = await FunctionContext <CreateSharedGroupRequest> .Create(req);

            // We have to use the MasterPlayerAccountId instead of the TitlePlayerAccountId to avoid errors during its addition as member of SGD
            var playerOne = context.CallerEntityProfile.Lineage.MasterPlayerAccountId;

            var sgdResponse = await SharedGroupDataUtil.CreateAsync(context.AuthenticationContext, context.FunctionArgument.SharedGroupId);

            await SharedGroupDataUtil.AddMembersAsync(context.AuthenticationContext, context.FunctionArgument.SharedGroupId, new List <string> {
                playerOne
            });

            var sharedGroupData = new TicTacToeSharedGroupData
            {
                SharedGroupId = sgdResponse.SharedGroupId,
                Match         = new Match {
                    PlayerOneId = playerOne
                }
            };

            return(await SharedGroupDataUtil.UpdateAsync(context.AuthenticationContext, sharedGroupData));
        }
Esempio n. 2
0
        public static async Task <TicTacToeSharedGroupData> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req)
        {
            var context = await FunctionContext <JoinMatchRequest> .Create(req);

            var playerId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId;

            await SharedGroupDataUtil.AddMembersAsync(context.AuthenticationContext, context.FunctionArgument.SharedGroupId, new List <string> {
                playerId
            });

            return(await MatchUtil.AddMember(context.AuthenticationContext, context.FunctionArgument.SharedGroupId, playerId));
        }