public async Task <IActionResult> PutTable(int id, Table table) { if (id != table.TableID) { return(BadRequest()); } _context.Entry(table).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TableExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Competition> > PutCompetition(int id, Competition competition) { if (id != competition.CompetitionID) { return(BadRequest()); } _context.Entry(competition).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompetitionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Delete(int id) { Player player = db.Players.Find(id); db.Entry(player).State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult <UserTeam> > ApproveUser(UserTeam userteam) { var approvedUserTeam = _context.UserTeam.Where(ut => ut.TeamID == userteam.TeamID && ut.UserID == userteam.UserID).SingleOrDefault(); approvedUserTeam.UserTeamStatusID = userteam.UserTeamStatusID; _context.Entry(approvedUserTeam).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult <User> > PutUser(int id, User user) { if (id != user.UserID) { return(BadRequest()); } var thisUser = _context.Users.Find(id); if (!user.Email.Equals(thisUser.Email)) { var users = await _context.Users.ToListAsync(); foreach (User checkUser in users) { if (checkUser.Email.Equals(user.Email)) { return(BadRequest(new { message = "This email is already in use." })); } } } _context.Entry(thisUser).State = EntityState.Detached; _context.UserRoles.RemoveRange(_context.UserRoles.Where(ur => ur.UserID == user.UserID).ToList()); foreach (var role in user.Roles) { UserRole userRole = new UserRole(); userRole.UserRoleID = 0; userRole.UserID = user.UserID; userRole.RoleID = role.RoleID; _context.UserRoles.Add(userRole); } _context.SaveChanges(); _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Create(int?id, Team team) { if (id != null) { db.Entry(team).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { db.Teams.Add(team); db.SaveChanges(); return(RedirectToAction("Index")); } }
async public Task <ActionResult> Edit(Player player) { db.Entry(player).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
//Edit private void button2_Click(object sender, EventArgs e) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Team team = db.Teams.Find(id); TeamForm tmForm = new TeamForm(); tmForm.textBox1.Text = team.Name; tmForm.textBox2.Text = team.Coach; DialogResult result = tmForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } team.Name = tmForm.textBox1.Text; team.Coach = tmForm.textBox2.Text; db.Entry(team).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Объект обновлен"); }
private void button2_Click(object sender, EventArgs e) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } // поиск команды Team team = db.Teams.Find(id); // создаем новую форму присваиваем поля TeamForm teamForm = new TeamForm(); teamForm.textBox1.Text = team.Name; teamForm.textBox3.Text = team.Coach; // выводим значение в форме DialogResult dialogResult = teamForm.ShowDialog(this); if (dialogResult == DialogResult.Cancel) { return; } // присваиваем новое значение team.Name = teamForm.textBox1.Text; team.Coach = teamForm.textBox3.Text; // сохраняем db.Entry(team).State = EntityState.Modified; db.SaveChanges(); // сообщаем MessageBox.Show("Запись обновлена"); }
private void buttonUpdate_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool convert = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (convert == false) { return; } Team team = db.Teams.Find(id); FormCreateTeam createTeam = new FormCreateTeam(); createTeam.textBoxTeamName.Text = team.Name; createTeam.textBoxCoach.Text = team.Coach; DialogResult result = createTeam.ShowDialog(this); if (result == DialogResult.Cancel) { return; } team.Name = createTeam.textBoxTeamName.Text; team.Coach = createTeam.textBoxCoach.Text; db.Entry(team).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Object was updated"); } }
public async Task <ActionResult <IEnumerable <TournamentTeam> > > AddTournamentTeam(TournamentTeam tournamentTeam) { var tournament = _context.Tournaments.Where(t => t.TournamentID == tournamentTeam.TournamentID).SingleOrDefault(); tournament.Total_Joined++; _context.Entry(tournament).State = EntityState.Modified; _context.TournamentTeams.Add(tournamentTeam); await _context.SaveChangesAsync(); return(Ok(tournamentTeam)); }
public async Task <ActionResult <Team> > DeleteTeam(int id) { var team = await _context.Teams.FindAsync(id); if (team == null) { return(NotFound()); } team.TeamStatusID = 4; _context.Entry(team).State = EntityState.Modified; await _context.SaveChangesAsync(); var userteams = _context.UserTeam.Where(ut => ut.TeamID == id).ToList(); foreach (var userteam in userteams) { _context.UserTeam.Remove(userteam); } _context.SaveChanges(); return(team); }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Player player = db.Players.Find(id); PlayerForm plForm = new PlayerForm(); plForm.numericUpDown1.Value = player.Age; plForm.comboBox1.SelectedItem = player.Position; plForm.textBox1.Text = player.Name; List <Team> teams = db.Teams.ToList(); plForm.comboBox2.DataSource = teams; plForm.comboBox2.ValueMember = "Id"; plForm.comboBox2.DisplayMember = "Name"; if (player.Team != null) { plForm.comboBox2.SelectedValue = player.Team.Id; } DialogResult result = plForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } player.Age = (int)plForm.numericUpDown1.Value; player.Name = plForm.textBox1.Text; player.Position = plForm.comboBox1.SelectedItem.ToString(); player.Team = (Team)plForm.comboBox2.SelectedItem; db.Entry(player).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Объект обновлен"); } }
public void Update(Player item) { _dataContext.Entry(item).State = EntityState.Modified; _dataContext.SaveChanges(); }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count < 1) { return; } if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Player player = db.Players.Find(id); PlayerForm playerForm = new PlayerForm(); playerForm.textBox1.Text = player.Name; playerForm.numericUpDown1.Value = player.Age; // получаем список команд List <Team> teams = db.Teams.ToList(); playerForm.listBox1.DataSource = teams; playerForm.listBox1.ValueMember = "Id"; playerForm.listBox1.DisplayMember = "Name"; foreach (Team item in player.Teams) { playerForm.listBox1.SelectedItem = item; } DialogResult dialogResult = playerForm.ShowDialog(this); // отмена if (dialogResult == DialogResult.Cancel) { return; } player.Age = (int)playerForm.numericUpDown1.Value; playerForm.Name = playerForm.textBox1.Text; // проверить наличие команд у игрока foreach (var team in teams) { if (playerForm.listBox1.SelectedItems.Contains(team)) { // если не содержит то добавляем if (!player.Teams.Contains(team)) { player.Teams.Add(team); } else { if (player.Teams.Contains(team)) { player.Teams.Remove(team); } } } } db.Entry(player).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Запись была изменена"); } }
public async Task <ActionResult <Tournament> > StartTournament(Tournament tournament) { var teams = _context.TournamentTeams.Where(tt => tt.TournamentID == tournament.TournamentID).ToList(); int count = tournament.Match_Count; int rounds = 1; for (int i = tournament.Match_Count / 2; i > 1; i /= 2) { rounds++; } for (int i = 1; i <= rounds; i++) { int k = 1; for (int j = 1; j <= count / 2; j++) { if (i == 1) { var match = new Match(); match.Score1 = 0; match.Score2 = 0; match.Date = DateTime.Now; match.TableID = 1; match.MatchTypeID = 1; match.Team1ID = teams[j - 1].TeamID; match.Team2ID = teams[teams.Count - j].TeamID; match.Player1ID = teams[j - 1].Player1ID; match.Player2ID = teams[j - 1].Player2ID; match.Player3ID = teams[teams.Count - j].Player1ID; match.Player4ID = teams[teams.Count - j].Player2ID; match.MatchStatusID = 6; match.TournamentID = tournament.TournamentID; match.Round = i; match.Number = j; match.NextRound = k; _context.Matches.Add(match); } else { var match = new Match(); match.Score1 = 0; match.Score2 = 0; match.Date = DateTime.Now; match.TableID = 1; match.MatchTypeID = 1; match.MatchStatusID = 6; match.TournamentID = tournament.TournamentID; match.Round = i; match.Number = j; match.NextRound = k; _context.Matches.Add(match); } if (j % 2 == 0) { k++; } } count /= 2; } tournament.isStart = true; _context.Entry(tournament).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(tournament)); }
public ActionResult Edit(Player player) { db.Entry(player).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
protected virtual void UpdateItem(T item) { Context.Entry(item).State = EntityState.Modified; }
public async Task <ActionResult <Match> > PutMatch(int id, Match match) { if (id != match.MatchID) { return(BadRequest()); } _context.Entry(match).State = EntityState.Modified; _context.SaveChanges(); if (match.MatchStatusID == 4) { if (match.Player1ID != null) { var user = _context.Users.Where(u => u.UserID == match.Player1ID).SingleOrDefault(); if (match.Score1 > match.Score2) { user.TimesWon++; } else { user.TimesLost++; } _context.Entry(user).State = EntityState.Modified; } if (match.Player2ID != null) { var user = _context.Users.Where(u => u.UserID == match.Player2ID).SingleOrDefault(); if (match.Score1 > match.Score2) { user.TimesWon++; } else { user.TimesLost++; } _context.Entry(user).State = EntityState.Modified; } if (match.Player3ID != null) { var user = _context.Users.Where(u => u.UserID == match.Player3ID).SingleOrDefault(); if (match.Score1 < match.Score2) { user.TimesWon++; } else { user.TimesLost++; } _context.Entry(user).State = EntityState.Modified; } if (match.Player4ID != null) { var user = _context.Users.Where(u => u.UserID == match.Player4ID).SingleOrDefault(); if (match.Score1 < match.Score2) { user.TimesWon++; } else { user.TimesLost++; } _context.Entry(user).State = EntityState.Modified; } //Check for next match if (match.TournamentID != null) { if (_context.Matches.Where(m => m.TournamentID == match.TournamentID && m.Round == (match.Round + 1)).Count() != 0) { var nextMatch = _context.Matches.Where(m => m.TournamentID == match.TournamentID && m.Round == (match.Round + 1) && m.Number == match.NextRound).SingleOrDefault(); var previousMatches = _context.Matches.Where(m => m.TournamentID == match.TournamentID && m.Round == match.Round && m.NextRound == match.NextRound).ToList(); var arrayNumber1 = 1; var arrayNumber2 = 0; if (previousMatches[0].MatchID == match.MatchID) { arrayNumber1 = 0; arrayNumber2 = 1; } if (previousMatches[arrayNumber1].Number < previousMatches[arrayNumber2].Number) { if (match.Score1 > match.Score2) { nextMatch.Team1ID = match.Team1ID; nextMatch.Player1ID = match.Player1ID; nextMatch.Player2ID = match.Player2ID; } else { nextMatch.Team1ID = match.Team2ID; nextMatch.Player1ID = match.Player3ID; nextMatch.Player2ID = match.Player4ID; } } else { if (match.Score1 > match.Score2) { nextMatch.Team2ID = match.Team1ID; nextMatch.Player3ID = match.Player1ID; nextMatch.Player4ID = match.Player2ID; } else { nextMatch.Team2ID = match.Team2ID; nextMatch.Player3ID = match.Player3ID; nextMatch.Player4ID = match.Player4ID; } } _context.Entry(nextMatch).State = EntityState.Modified; } else { var tournament = _context.Tournaments.Where(t => t.TournamentID == match.TournamentID).SingleOrDefault(); tournament.isStart = false; if (match.Score1 > match.Score2) { var name = _context.Teams.Where(t => t.TeamID == match.Team1ID).SingleOrDefault().TeamName; tournament.Winner = name; } else { var name = _context.Teams.Where(t => t.TeamID == match.Team2ID).SingleOrDefault().TeamName; tournament.Winner = name; } _context.Entry(tournament).State = EntityState.Modified; _context.SaveChanges(); } } } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MatchExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Update(Team team) { _dataContext.Entry(team).State = EntityState.Modified; _dataContext.SaveChanges(); }