Esempio n. 1
0
        public ActionResult Team(int id)
        {
            var model = new TeamModel();

            model.TeamId = id;
            // Load scores
            using (SqlConnection con = new SqlConnection(_connectionString))
            {
                con.Open();
                try
                {
                    using (SqlCommand command = new SqlCommand("select name from sturgeonteams where id = @team_id", con))
                    {
                        command.Parameters.Add(new SqlParameter("team_id", model.TeamId));
                        var reader = command.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                model.TeamName = reader.GetString(0);
                            }
                        }
                        reader.Close();
                    }

                    using (SqlCommand command = new SqlCommand("select slot, score from sturgeonscores where team_id = @team_id", con))
                    {
                        command.Parameters.Add(new SqlParameter("team_id", model.TeamId));
                        var reader = command.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                model.SetScore(reader.GetInt32(0), reader.GetInt32(1));
                            }
                        }
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(View(model));
        }