Exemple #1
0
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            graphQLQuery.FieldAsync <ResponseGraphType <MapType> >(
                "map",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType>()
            {
                Name = "mapId"
            }),
                resolve: async context =>
            {
                var id          = context.GetArgument <Guid>("mapId");
                var mapFromRepo = await _playerRepository.GetMapByIdAsync(id);
                var mapToRetun  = Mapper.Map <MapDto>(mapFromRepo);
                return(Response(mapToRetun));
            });

            graphQLQuery.FieldAsync <ResponseListGraphType <MapType> >(
                "maps",
                resolve: async context =>
            {
                var mapsFromRepo = await _playerRepository.GetAllMapsAsync();
                var mapsToReturn = Mapper.Map <IEnumerable <MapDto> >(mapsFromRepo);
                return(Response(mapsToReturn));
            });

            graphQLQuery.FieldAsync <ResponseGraphType <MapType> >(
                "createMap",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <MapInputType> > {
                Name = "map"
            }
                    ),
                resolve: async context =>
            {
                var map       = context.GetArgument <MapForCreationDto>("map");
                var mapEntity = Mapper.Map <Map>(map);
                await _playerRepository.AddMapAsync(mapEntity);
                var mapToReturn = Mapper.Map <MapDto>(mapEntity);
                return(Response(mapToReturn));
            });

            graphQLQuery.FieldAsync <ResponseGraphType <MapType> >(
                "updateMap",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <MapInputType> > {
                Name = "map"
            }
                    ),
                resolve: async context =>
            {
                var map       = context.GetArgument <MapForManipulationDto>("map");
                var mapEntity = Mapper.Map <Map>(map);
                await _playerRepository.UpdateMapAsync(mapEntity);
                var mapToReturn = Mapper.Map <MapDto>(mapEntity);
                return(Response(mapToReturn));
            });
        }
Exemple #2
0
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            var language = _accessor.HttpContext.Items["language"] as LanguageDTO;

            graphQLQuery.FieldAsync <ResponseGraphType <CountryGroupResultType> >(
                "countrygroupsresponse",
                arguments: new QueryArguments
                (
                    new QueryArgument <IdGraphType> {
                Name = "pageNo", Description = "page number"
            },
                    new QueryArgument <IdGraphType> {
                Name = "pageSize", Description = "page size"
            }
                ),
                resolve: async context =>
            {
                var pageNo   = context.GetArgument <int>("pageNo") == 0 ? 1 : context.GetArgument <int>("pageNo");
                var pageSize = context.GetArgument <int>("pageSize") == 0 ? 100 : context.GetArgument <int>("pageSize");
                if (language != null)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetCountryGroups",
                                                                                   () => _countryGroupService.GetCountryGroupsAsync(language, pageNo, pageSize));
                    var list = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(list));
                }
                return(null);
            }
                , description: "All CountryGroups data"
                );

            graphQLQuery.FieldAsync <ResponseGraphType <CountryGroupType> >(
                "countrygroup",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "countryGroupId", Description = "id of the countryGroup"
            }
                    ),
                resolve: async context =>
            {
                var countryGroupId = context.GetArgument <int>("countryGroupId");
                if (language != null && countryGroupId > 0)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetCountryGroup",
                                                                                   () => _countryGroupService.GetCountryGroupAsync(language, countryGroupId));
                    var countryGroupDetails = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(countryGroupDetails));
                }

                return(null);
            }
                );
        }
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            graphQLQuery.FieldAsync <ResponseGraphType <ResourceGroupResultType> >(
                "resourcegroupsresponse",
                arguments: new QueryArguments
                (
                    new QueryArgument <IdGraphType> {
                Name = "pageNo", Description = "page number"
            },
                    new QueryArgument <IdGraphType> {
                Name = "pageSize", Description = "page size"
            }
                ),
                resolve: async context =>
            {
                var pageNo   = context.GetArgument <int>("pageNo") == 0 ? 1 : context.GetArgument <int>("pageNo");
                var pageSize = context.GetArgument <int>("pageSize") == 0 ? 10000 : context.GetArgument <int>("pageSize");

                var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetResourceGroups",
                                                                               () => _resourceGroupService.GetResourceGroupsAsync(pageNo, pageSize));
                var list = await context.TryAsyncResolve(
                    async c => await loader.LoadAsync());
                return(Response(list));
            }
                , description: "All ResourceGroups data"
                );

            graphQLQuery.FieldAsync <ResponseGraphType <ResourceGroupType> >(
                "resourcegroup",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "resourceGroupId", Description = "id of the resourcegroup"
            }
                    ),
                resolve: async context =>
            {
                var resourceGroupId = context.GetArgument <int>("resourceGroupId");
                if (resourceGroupId > 0)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetResourceGroup",
                                                                                   () => _resourceGroupService.GetResourceGroupAsync(resourceGroupId));
                    var resourceGroupDetails = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(resourceGroupDetails));
                }

                return(null);
            }
                );
        }
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            graphQLQuery.FieldAsync <ResponseGraphType <ArticleType> >(
                "article",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "articleId", Description = "id of the article"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "countryId", Description = "id of the country "
            }
                    ),
                resolve: async context =>
            {
                var articleId    = context.GetArgument <int>("articleId");
                var countryId    = context.GetArgument <int>("countryId");
                var userCookieId = _utilityService.GetCookieId(_accessor.HttpContext.Request);

                if (articleId > 0 && countryId > 0)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetArticle",
                                                                                   () => _articleService.GetArticleAsync(articleId, countryId, userCookieId));
                    var articleDetails = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(articleDetails));
                }

                return(null);
            }
                );
        }
Exemple #5
0
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            graphQLQuery.FieldAsync <ResponseGraphType <CountryResultType> >(
                "countriesresponse",
                //arguments: new QueryArguments
                //(
                //    new QueryArgument<IdGraphType> { Name = "pageNo", Description = "page number" },
                //    new QueryArgument<IdGraphType> { Name = "pageSize", Description = "page size" }
                //),
                resolve: async context =>
            {
                //var pageNo = context.GetArgument<int>("pageNo") == 0 ? 1 : context.GetArgument<int>("pageNo");
                //var pageSize = context.GetArgument<int>("pageSize") == 0 ? 10000 : context.GetArgument<int>("pageSize");

                var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetAllCountries",
                                                                               () => _countryService.GetAllCountriesAsync());
                var list = await context.TryAsyncResolve(
                    async c => await loader.LoadAsync());
                return(Response(list));
            }
                , description: "All Countries data"
                );

            graphQLQuery.FieldAsync <ResponseGraphType <CountryType> >(
                "country",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "countryId", Description = "id of the country"
            }
                    ),
                resolve: async context =>
            {
                var countryId = context.GetArgument <int>("countryId");
                if (countryId > 0)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetCountry",
                                                                                   () => _countryService.GetCountryAsync(countryId));
                    var countryDetails = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(countryDetails));
                }

                return(null);
            }
                );
        }
Exemple #6
0
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            var language = _accessor.HttpContext.Items["language"] as LanguageDTO;

            graphQLQuery.FieldAsync <ResponseGraphType <TaxTagGroupResultType> >(
                "taxtaggroupsresponse",
                resolve: async context =>
            {
                if (language != null)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetTaxTagGroups",
                                                                                   () => _taxTagsService.GetTaxTagGroupsAsync(language));
                    var list = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(list));
                }
                return(null);
            }
                , description: "All TaxTagGroups data"
                );

            graphQLQuery.FieldAsync <ResponseGraphType <TaxTagGroupType> >(
                "taxtaggroup",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "taxTagId", Description = "id of the taxTagGroup"
            }
                    ),
                resolve: async context =>
            {
                var taxTagId = context.GetArgument <int>("taxTagId");
                if (language != null && taxTagId > 0)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetTaxTagGroup",
                                                                                   () => _taxTagsService.GetTaxTagGroupAsync(language, taxTagId));
                    var taxTagGroupDetails = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(taxTagGroupDetails));
                }

                return(null);
            }
                );
        }
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            var language = _accessor.HttpContext.Items["language"] as LanguageDTO;

            graphQLQuery.FieldAsync <ResponseGraphType <CountryResultType> >(
                "countriesresponse",
                resolve: async context =>
            {
                if (language != null)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetAllCountries",
                                                                                   () => _countryService.GetAllCountriesAsync(language));
                    var list = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(list));
                }
                return(null);
            }
                , description: "All Countries data"
                );

            graphQLQuery.FieldAsync <ResponseGraphType <CountryType> >(
                "country",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "countryId", Description = "id of the country"
            }
                    ),
                resolve: async context => {
                var countryId = context.GetArgument <int>("countryId");
                if (language != null && countryId > 0)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetCountry",
                                                                                   () => _countryService.GetCountryAsync(language, countryId));
                    var countryDetails = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(countryDetails));
                }

                return(null);
            }
                );
        }
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            graphQLQuery.FieldAsync <ResponseGraphType <RoundType> >(
                "round",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "roundId"
            }
                    ),
                resolve: async context =>
            {
                var id            = context.GetArgument <Guid>("roundId");
                var roundFromRepo = await _playerRepository.GetRoundById(id);
                var roundToReturn = Mapper.Map <RoundDto>(roundFromRepo);
                return(Response(roundToReturn));
            });

            graphQLQuery.FieldAsync <ResponseListGraphType <RoundType> >(
                "rounds",
                resolve: async context =>
            {
                var roundsFromRepo = await _playerRepository.GetAllRoundsAsync();
                var roundsToReturn = Mapper.Map <IEnumerable <RoundDto> >(roundsFromRepo);
                return(Response(roundsToReturn));
            });

            graphQLQuery.FieldAsync <ResponseGraphType <RoundType> >(
                "createRound",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <RoundInputType> > {
                Name = "round"
            }
                    ),
                resolve: async context =>
            {
                var round         = context.GetArgument <RoundForCreationDto>("round");
                var roundEntity   = Mapper.Map <Round>(round);
                var addedRound    = await _playerRepository.AddRoundAsync(roundEntity);
                var roundToReturn = Mapper.Map <RoundDto>(addedRound);
                return(Response(roundToReturn));
            });
        }
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            graphQLQuery.FieldAsync <ResponseGraphType <DisclaimerResultType> >(
                "disclaimersresponse",
                resolve: async context =>
            {
                var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetAllDisclaimers",
                                                                               () => _disclaimerService.GetAllDisclaimersAsync());
                var list = await context.TryAsyncResolve(
                    async c => await loader.LoadAsync());
                return(Response(list));
            }
                , description: "All Disclaimers data"
                );

            graphQLQuery.FieldAsync <ResponseGraphType <DisclaimerType> >(
                "disclaimer",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "disclaimerId", Description = "id of the disclaimer"
            }
                    ),
                resolve: async context =>
            {
                var disclaimerId = context.GetArgument <int>("disclaimerId");
                if (disclaimerId > 0)
                {
                    var loader = _dataLoaderContextAccessor.Context.GetOrAddLoader("GetDisclaimer",
                                                                                   () => _disclaimerService.GetDiscalimerAsync(disclaimerId));
                    var disclaimerDetails = await context.TryAsyncResolve(
                        async c => await loader.LoadAsync());
                    return(Response(disclaimerDetails));
                }

                return(null);
            }
                );
        }
Exemple #10
0
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            graphQLQuery.FieldAsync <ResponseGraphType <PlayerType> >(
                "player",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType>()
            {
                Name = "playerId"
            }),
                resolve: async context =>
            {
                var id            = context.GetArgument <Guid>("playerId");
                var playerForRepo = await _playerRepository.GetByIdAsync(id);

                if (playerForRepo == null)
                {
                    return(NotFoundError(id.ToString()));
                }

                var playerToReturn = Mapper.Map <PlayerDto>(playerForRepo);
                return(Response(playerToReturn));
            });

            graphQLQuery.FieldAsync <ResponseGraphType <PlayerType> >(
                "playerByName",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "name"
            }),
                resolve: async context =>
            {
                var name           = context.GetArgument <string>("name");
                var playerForRepo  = await _playerRepository.GetByNameAsync(name);
                var playerToReturn = Mapper.Map <PlayerDto>(playerForRepo);
                return(Response(playerToReturn));
            });

            graphQLQuery.FieldAsync <ResponseListGraphType <PlayerType> >(
                "players",
                resolve: async context =>
            {
                var playersFromRepo = await _playerRepository.GetAllPlayersAsync();
                var playersToReturn = Mapper.Map <IEnumerable <PlayerDto> >(playersFromRepo);
                return(Response(playersToReturn));
            });

            graphQLQuery.FieldAsync <ResponseGraphType <PlayerType> >(
                "createPlayer",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PlayerInputType> > {
                Name = "player"
            }
                    ),
                resolve: async context =>
            {
                var player = context.GetArgument <PlayerForCreationDto>("player");
                Player playerFromRepo;

                if (await _playerRepository.CheckIfPlayerNameExists(player.Name))
                {
                    playerFromRepo = await _playerRepository.GetByNameAsync(player.Name);
                }
                else
                {
                    var playerEntity = Mapper.Map <Player>(player);
                    playerFromRepo   = await _playerRepository.AddPlayerAsync(playerEntity);
                }

                var playerToReturn = Mapper.Map <PlayerDto>(playerFromRepo);
                return(Response(playerToReturn));
            });

            graphQLQuery.FieldAsync <ResponseGraphType <PlayerType> >(
                "updatePlayer",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PlayerInputType> > {
                Name = "player"
            }
                    ),
                resolve: async context =>
            {
                var player       = context.GetArgument <PlayerForManipulationDto>("player");
                var playerEntity = Mapper.Map <Player>(player);
                await _playerRepository.UpdatePlayerAsync(playerEntity);
                var playerToReturn = Mapper.Map <PlayerDto>(playerEntity);
                return(Response(playerToReturn));
            });
        }