Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        public async Task UpdateSeasonEntry(SeasonEntryEditModel seasonEntry)
        {
            if (seasonEntry == null)
            {
                throw new ArgumentNullException(nameof(seasonEntry));
            }

            await _queryExecutor
            .NewQuery("UPDATE [dbo].[SeasonEntry] SET Name=@Name WHERE [Season]=@Season AND [Team]=@Team")
            .WithCommandType(CommandType.Text)
            .WithParameters(new {
                Season = seasonEntry.Season,
                Team   = seasonEntry.Team,
                Name   = seasonEntry.Name
            })
            .ExecuteAsync();
        }