public IActionResult OnPostSave(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            var tournament = tournamentRepository.Get(id.Value);

            if (tournament == null)
            {
                return(NotFound());
            }

            if (tournament.Name != ViewModel.Name)
            {
                tournament.Name = ViewModel.Name;
            }

            if (tournament.DueDate != ViewModel.DueDate)
            {
                tournament.DueDate = ViewModel.DueDate;
            }

            if (tournament.Desc != ViewModel.Desc)
            {
                tournament.Desc = ViewModel.Desc;
            }

            tournamentRepository.Update(tournament);

            return(OnGet(id));
        }
示例#2
0
        public SCQuery(
            LeagueRepository leagueRepository,
            PlayerRepository playerRepository,
            TournamentRepository tournamentRepository,
            FrameRepository frameRepository,
            UserRepository userRepository,
            SettingRepository settingRepository
            )
        {
            // Leagues
            Field <ListGraphType <LeagueType> >(
                "leagues",
                resolve: context => leagueRepository.Get(null, p => p.OrderBy(p => p.DisplayName))
                );
            Field <LeagueType>(
                "league",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                resolve: context => leagueRepository.GetById(context.GetArgument <Guid>("id"))
                );

            // Players
            Field <ListGraphType <PlayerType> >(
                "players",
                resolve: context => playerRepository.Get(null, p => p.OrderBy(p => p.FirstName))
                );
            Field <PlayerType>(
                "player",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                resolve: context => playerRepository.GetById(context.GetArgument <Guid>("id"))
                );

            // Tournaments
            Field <ListGraphType <TournamentType> >(
                "tournaments",
                resolve: context => tournamentRepository.Get(null, t => t.OrderByDescending(t => t.Date))
                );
            Field <TournamentType>(
                "tournament",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                resolve: context => tournamentRepository.GetById(context.GetArgument <Guid>("id"))
                );

            // Frames
            Field <ListGraphType <FrameType> >(
                "frames",
                resolve: context => frameRepository.Get(null, t => t.OrderByDescending(t => t.EndDate))
                );
            Field <FrameType>(
                "frame",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                resolve: context => frameRepository.GetById(context.GetArgument <Guid>("id"))
                );

            // Users
            Field <ListGraphType <UserType> >(
                "users",
                resolve: context =>
            {
                // TODO
                //ClaimsPrincipal user = (ClaimsPrincipal)context.UserContext;
                //if (!user.IsInRole("Admin")) { return null; }

                return(userRepository.Get());
            }
                );
            Field <UserType>(
                "user",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                resolve: context =>
            {
                // TODO
                //ClaimsPrincipal user = (ClaimsPrincipal)context.UserContext;
                //if (!user.IsInRole("Admin")) { return null; }

                return(userRepository.GetById(context.GetArgument <Guid>("id")));
            }
                );

            // Settings
            Field <ListGraphType <SettingType> >(
                "settings",
                resolve: context => settingRepository.Get(null, s => s.OrderByDescending(s => s.Key))
                );
            Field <SettingType>(
                "setting",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "key"
            }),
                resolve: context => settingRepository.GetByKey(context.GetArgument <string>("key"))
                );
        }