Exemple #1
0
        public List <Category> GetAll()
        {
            var        categoryList = new List <Category>();
            SqlCommand cmd          = new SqlCommand("Select * from Categories");

            SqlDataReader reader = VTYS.SqlExecuteReader(cmd);

            while (reader.Read())
            {
                Category category = new Category()
                {
                    CategoryId   = Convert.ToInt32(reader[0]),
                    CategoryName = reader[1].ToString(),
                };

                categoryList.Add(category);
            }
            return(categoryList);
        }
Exemple #2
0
        public Category Get(int id)
        {
            SqlCommand cmd = new SqlCommand("Select * from Categories where Id = @CategoryId");

            cmd.Parameters.AddWithValue("CategoryId", id);

            SqlDataReader reader = VTYS.SqlExecuteReader(cmd);

            while (reader.Read())
            {
                Category category = new Category()
                {
                    CategoryId   = Convert.ToInt32(reader[0]),
                    CategoryName = reader[1].ToString(),
                };

                return(category);
            }
            return(null);
        }
Exemple #3
0
        public List <Book> GetAll()
        {
            var        bookList = new List <Book>();
            SqlCommand cmd      = new SqlCommand("Select * from Books");

            SqlDataReader reader = VTYS.SqlExecuteReader(cmd);

            while (reader.Read())
            {
                Book book = new Book
                {
                    Id          = Convert.ToInt32(reader[0]),
                    Title       = reader[1].ToString(),
                    Description = reader[2].ToString(),
                    Price       = Convert.ToDecimal(reader[3]),
                    CategoryId  = Convert.ToInt32(reader[4])
                };

                bookList.Add(book);
            }
            return(bookList);
        }
Exemple #4
0
        public Book Get(int id)
        {
            SqlCommand cmd = new SqlCommand("Select * from Books where Id = @Id");

            cmd.Parameters.AddWithValue("Id", id);

            SqlDataReader reader = VTYS.SqlExecuteReader(cmd);

            while (reader.Read())
            {
                Book book = new Book
                {
                    Id          = Convert.ToInt32(reader[0]),
                    Title       = reader[1].ToString(),
                    Description = reader[2].ToString(),
                    Price       = Convert.ToDecimal(reader[3]),
                    CategoryId  = Convert.ToInt32(reader[4])
                };

                return(book);
            }
            return(null);
        }