public ActionResult Teams(string id) { int teamId; Team team = new Team(); try { CheckUser(Models.Content.Teams); if (int.TryParse(id, out teamId)) { team = _data.GetTeamById(teamId); } } catch (Exception ex) { ErrorLog.WriteError("Edit Team", ex.Message); } return View(team); }
public bool CheckIfTeamExists(Team team) { using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["IYFD"].ToString())) { connection.Open(); using (SqlCommand cmd = new SqlCommand("dbo.CheckTeamName", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", team.Name); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { return true; } else { return false; } } } } }
public ActionResult Teams(string id, string name) { try { CheckUser(Models.Content.Teams); int teamId; if (int.TryParse(id, out teamId)) { Team team = new Team { ID = teamId, Name = name }; _data.UpsertTeam(team); } } catch (Exception ex) { ErrorLog.WriteError("Edit Team", ex.Message); } return RedirectToAction("Teams", "Admin"); }
public Team GetTeamById(int teamId) { Team team = new Team(); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["IYFD"].ToString())) { connection.Open(); using (SqlCommand cmd = new SqlCommand("dbo.GetTeamById", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@teamId", teamId); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { team.ID = Convert.ToInt32(reader["id"]); team.Name = reader["name"].ToString(); } } } } return team; }
public bool UpsertTeam(Team team) { int rows = 0; using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["IYFD"].ToString())) { connection.Open(); using (SqlCommand cmd = new SqlCommand("dbo.UpsertTeam", connection)) { cmd.CommandType = CommandType.StoredProcedure; if(team.ID != null) cmd.Parameters.AddWithValue("@ID", team.ID); cmd.Parameters.AddWithValue("@name", team.Name); rows = cmd.ExecuteNonQuery(); } } return rows > 0; }