Ejemplo n.º 1
0
        public CyclistTeam Get(int id)
        {
            var queryData = new SqlQueryData("SELECT * FROM cyclist_team WHERE [id] = @id", QueryType.Reader);

            queryData.AddParameter("@id", SqlDbType.VarChar, Convert.ToString(id));

            var         builder = new CyclistTeamBuilder();
            CyclistTeam team    = null;

            try
            {
                SqlDataReader reader = crud.Get(queryData);

                while (reader.Read())
                {
                    team = builder
                           .SetId(id)
                           .SetName(reader.GetString(1))
                           .SetCountry(reader.GetString(2))
                           .Build();
                }

                return(team ?? new CyclistTeam());
            }
            catch (Exception e)
            {
                MessageBox.Show("Unable to retrieve team. " + e.Message, "CyclistRegistration team error type: " +
                                e.GetType(), MessageBoxButton.OK, MessageBoxImage.Error);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
                return(new CyclistTeam());
            }
        }
Ejemplo n.º 2
0
        public List <CyclistTeam> GetAll()
        {
            var queryData = new SqlQueryData("SELECT * FROM cyclist_team", QueryType.Reader);
            var builder   = new CyclistTeamBuilder();

            var allTeams = new List <CyclistTeam>();

            try
            {
                SqlDataReader reader = crud.Get(queryData);

                while (reader.Read())
                {
                    CyclistTeam team = builder
                                       .SetId(reader.GetInt32(0))
                                       .SetName(reader.GetString(1))
                                       .SetCountry(reader.GetString(2))
                                       .Build();

                    allTeams.Add(team);
                }

                reader.Close();
                return(allTeams);
            }
            catch (Exception e)
            {
                MessageBox.Show("Unable to retrieve team. " + e.Message, "CyclistRegistration team error type: " +
                                e.GetType(), MessageBoxButton.OK, MessageBoxImage.Error);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
                return(allTeams);
            }
        }