Example #1
0
        public async Task <ActionResult <Game> > PostGame(GameModel model)
        {
            try
            {
                var location = _linkGenerator.GetPathByAction("GetGame", "Games", new { id = -1 });
                if (string.IsNullOrWhiteSpace(location))
                {
                    return(BadRequest("Could not use ID"));
                }

                var game = _mapper.Map <Game>(model);

                await _gameService.AddGameAsync(game);

                if (await _sharedRepository.SaveChangesAsync() > 0)
                {
                    return(Created(location, _mapper.Map <GameModel>(game)));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, Settings.DatabaseFailureString));
            }
        }
        public async Task <ActionResult <TeamSeason> > PostTeamSeason(TeamSeasonModel model)
        {
            try
            {
                var location = _linkGenerator.GetPathByAction("GetTeamSeason", "TeamSeasons", new { id = -1 });
                if (string.IsNullOrWhiteSpace(location))
                {
                    return(BadRequest("Could not use ID"));
                }

                var teamSeason = _mapper.Map <TeamSeason>(model);

                await _teamSeasonRepository.AddAsync(teamSeason);

                if (await _sharedRepository.SaveChangesAsync() > 0)
                {
                    return(Created(location, _mapper.Map <TeamSeasonModel>(teamSeason)));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, Settings.DatabaseFailureString));
            }
        }
        public async Task <IActionResult> Create([Bind("LongName,ShortName,FirstSeasonYear,LastSeasonYear")] League league)
        {
            if (ModelState.IsValid)
            {
                await _leagueRepository.AddAsync(league);

                await _sharedRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(league));
        }
        public async Task <IActionResult> Create([Bind("SeasonYear,Week,GuestName,GuestScore,HostName,HostScore,WinnerName,WinnerScore,LoserName,LoserScore,IsPlayoffGame,Notes")] Game game)
        {
            if (ModelState.IsValid)
            {
                await _gameService.AddGameAsync(game);

                await _sharedRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(Create)));
            }

            return(View(game));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("TeamName,SeasonYear,LeagueName")] TeamSeason teamSeason)
        {
            if (ModelState.IsValid)
            {
                await _teamSeasonRepository.AddAsync(teamSeason);

                await _sharedRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(teamSeason));
        }
        public async Task <IActionResult> Create([Bind("Year,NumOfWeeksScheduled,NumOfWeeksCompleted")] Season season)
        {
            if (ModelState.IsValid)
            {
                await _seasonRepository.AddAsync(season);

                await _sharedRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(season));
        }
        public async Task <IActionResult> Create([Bind("LeagueName,SeasonYear,TotalGames,TotalPoints,AveragePoints")] LeagueSeason leagueSeason)
        {
            if (ModelState.IsValid)
            {
                await _leagueSeasonRepository.AddAsync(leagueSeason);

                await _sharedRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(leagueSeason));
        }
Example #8
0
        /// <summary>
        /// Adds a <see cref="Game"/> entity to the data store asynchronously.
        /// </summary>
        /// <param name="newGame">The <see cref="Game"/> entity to add to the data store.</param>
        public async Task AddGameAsync(Game newGame)
        {
            Guard.ThrowIfNull(newGame, $"{GetType()}.{nameof(AddGameAsync)}: {nameof(newGame)}");

            var newGameDecorator = new GameDecorator(newGame);

            newGameDecorator.DecideWinnerAndLoser();

            await _gameRepository.AddAsync(newGame);

            await EditTeamsAsync(Direction.Up, newGameDecorator);

            await _sharedRepository.SaveChangesAsync();
        }
Example #9
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _leagueRepository.Update(League);

            try
            {
                await _sharedRepository.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!(await _leagueRepository.LeagueExists(League.ID)))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        /// <summary>
        /// Runs a weekly update of the data store.
        /// </summary>
        public async Task RunWeeklyUpdate(int seasonYear)
        {
            // These hard-coded values are a bit of a hack at this time, but I intend to make them selectable by the
            // user in the future.
            var leagueName = "APFA";

            await UpdateLeagueSeason(leagueName, seasonYear);

            var srcWeekCount = await UpdateWeekCount(seasonYear);

            await _sharedRepository.SaveChangesAsync();

            if (srcWeekCount >= 3)
            {
                await UpdateRankings();
            }
        }
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _leagueRepository.AddAsync(League);

            await _sharedRepository.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #12
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id is null)
            {
                return(NotFound());
            }

            League = await _leagueRepository.GetLeagueAsync(id.Value);

            if (!(League is null))
            {
                await _leagueRepository.DeleteAsync(League.ID);

                await _sharedRepository.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }