private void AddFootballer() { var footballer = new FootballerModel(TextBoxFirstName, TextBoxLastName, SliderWeight, SliderAge); _footballerList.Add(footballer); FootballerSerialization.SaveTo(serializationPath, FootballerList.ToList()); }
private void EditFootballer() { var footballer = new FootballerModel(TextBoxFirstName, TextBoxLastName, SliderWeight, SliderAge); var dialogResult = MessageBox.Show($"Czy na pewno chcesz zmienić dane{Environment.NewLine}obiektu \"{FootballerList[SelectedFootIndex]}\"?", "Edytuj", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { FootballerList.Insert(SelectedFootIndex, footballer); SelectedFootIndex -= 1; FootballerList.RemoveAt(SelectedFootIndex + 1); FootballerSerialization.SaveTo(serializationPath, FootballerList.ToList()); } }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var footballer = await _context.Footballers.FindAsync(id); if (footballer == null) { return(NotFound()); } var footballerModel = new FootballerModel { Footballer = footballer, Teams = _context.Teams }; return(View(footballerModel)); }
public async Task <IActionResult> Edit( int id, [Bind("Id,Name,Surname,Gender,DateOfBirth,TeamName,Country")] Footballer footballer) { if (id != footballer.Id) { return(NotFound()); } if (ModelState.IsValid) { try { footballer.Team = _context.Teams.Any(t => t.Name == footballer.TeamName) ? _context.Teams.Single(t => t.Name == footballer.TeamName) : new Team { Name = footballer.TeamName }; _context.Update(footballer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FootballerExists(footballer.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var footballerModel = new FootballerModel { Footballer = footballer, Teams = _context.Teams }; return(View(footballerModel)); }
public async Task <IActionResult> Create( [Bind("Id,Name,Surname,Gender,DateOfBirth,TeamName,Country")] Footballer footballer) { if (ModelState.IsValid) { footballer.Team = _context.Teams.Any(t => t.Name == footballer.TeamName) ? _context.Teams.Single(t => t.Name == footballer.TeamName) : new Team { Name = footballer.TeamName }; _context.Add(footballer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } var footballerModel = new FootballerModel { Footballer = footballer, Teams = _context.Teams }; return(View(footballerModel)); }