Exemple #1
0
        public async Task <ActionResult <TeamSeason> > PostLeague(LeagueModel model)
        {
            try
            {
                var location = _linkGenerator.GetPathByAction("GetLeague", "Leagues", new { id = -1 });
                if (string.IsNullOrWhiteSpace(location))
                {
                    return(BadRequest("Could not use ID"));
                }

                var league = _mapper.Map <League>(model);

                await _leagueRepository.AddAsync(league);

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

                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));
        }
        // 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"));
        }