Example #1
0
 public SeasonEntryDisplayModel(
     SeasonEntry seasonEntry,
     IEnumerable <Team> teams = null)
 {
     DataModel      = seasonEntry ?? throw new ArgumentNullException(nameof(seasonEntry));
     AvailableTeams = teams;
 }
        public async Task <IActionResult> Edit(int?id, [Bind("Season,Team,Name")][ModelBinder(typeof(SeasonEntryEditModel.SeasonEntryEditModelBinder))] SeasonEntryEditModel seasonEntry)
        {
            if (id == null)
            {
                return(NotFound());
            }
            if (id != seasonEntry.Season)
            {
                return(NotFound());
            }

            var seasonEntryForValidation = new SeasonEntry {
                Season = seasonEntry.Season,
                Team   = seasonEntry.Team,
                Name   = seasonEntry.Name
            };
            await _seasonEntryModelStatePopulator.ValidateAndPopulateForUpdate(
                ModelState,
                new SeasonEntry.SeasonEntryKey(seasonEntry.Season, seasonEntry.Team),
                seasonEntryForValidation);

            if (ModelState.IsValid)
            {
                await _seasonEntryService.UpdateSeasonEntry(seasonEntry);

                return(RedirectToAction(nameof(Index), new { id = seasonEntry.Season }));
            }

            return(View(await _seasonEntryService.LoadDisplayModel(seasonEntry.Season, seasonEntry.Team)));
        }
        public async Task <IActionResult> Create(int?id, [Bind("Season,Team,Name")] SeasonEntry seasonEntry)
        {
            if (id == null)
            {
                return(NotFound());
            }

            await _seasonEntryModelStatePopulator.ValidateAndPopulateForCreate(ModelState, seasonEntry);

            if (ModelState.IsValid)
            {
                await _seasonEntryService.PersistSeasonEntry(seasonEntry);

                return(RedirectToAction(nameof(Index), new { id = id.Value }));
            }

            var seasonEntryDisplayModel = await _seasonEntryService.GetNew(id.Value);

            if (seasonEntryDisplayModel == null)
            {
                return(NotFound());
            }
            return(View(seasonEntryDisplayModel));
        }
 public async Task PersistSeasonEntry(SeasonEntry seasonEntry)
 {
     _context.Add(seasonEntry);
     await _context.SaveChangesAsync();
 }