Exemple #1
0
        public Chat GetById(int id)
        {
            try
            {
                using (var con = new SqlConnection(Env.ConnectionString))
                {
                    con.Open();
                    var cmdString = "SELECT * FROM Chatbericht WHERE Id = @id";
                    var command   = new SqlCommand(cmdString, con);
                    command.Parameters.AddWithValue("@id", id);
                    var reader = command.ExecuteReader();

                    Chat chat = null;

                    while (reader.Read())
                    {
                        var gsql  = new GebruikerSqlContext();
                        var grepo = new GebruikerRepository(gsql);
                        var g1    = grepo.GetById(reader.GetInt32(1));
                        var g2    = grepo.GetById(reader.GetInt32(2));
                        chat = new Chat(reader.GetInt32(0), g1, g2, reader.GetDateTime(3), reader.GetString(4));
                    }
                    con.Close();
                    return(chat);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #2
0
        public List <Chat> GetAll()
        {
            try
            {
                List <Chat> chats = new List <Chat>();
                using (var con = new SqlConnection(Env.ConnectionString))
                {
                    con.Open();
                    var cmdString = "SELECT * FROM Chatbericht";
                    var command   = new SqlCommand(cmdString, con);

                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        var gsql  = new GebruikerSqlContext();
                        var grepo = new GebruikerRepository(gsql);
                        var g1    = grepo.GetById(reader.GetInt32(1));
                        var g2    = grepo.GetById(reader.GetInt32(2));
                        var chat  = new Chat(reader.GetInt32(0), g1, g2, reader.GetDateTime(3), reader.GetString(4));
                        chats.Add(chat);
                    }
                    con.Close();
                    return(chats);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }