Beispiel #1
0
 public void Add(Category entity)
 {
     using (SqlCommand cmd = new SqlCommand("INSERT INTO Categories VALUES (@CategoryName)"))
     {
         cmd.Parameters.AddWithValue("CategoryName", entity.CategoryName);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #2
0
 public void Delete(Book entity)
 {
     using (SqlCommand cmd =
                new SqlCommand("DELETE FROM Books where Id = @Id"))
     {
         cmd.Parameters.AddWithValue("Id", entity.Id);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #3
0
 public void Delete(Category entity)
 {
     using (SqlCommand cmd =
                new SqlCommand("DELETE FROM Categories where CategoryId = @CategoryId"))
     {
         cmd.Parameters.AddWithValue("Id", entity.CategoryId);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #4
0
 public void Update(Category entity)
 {
     using (SqlCommand cmd =
                new SqlCommand("UPDATE Categories set CategoryId = @CategoryId, CategoryName = @CategoryName,  where CategoryId = @CategoryId"))
     {
         cmd.Parameters.AddWithValue("CategoryId", entity.CategoryId);
         cmd.Parameters.AddWithValue("CategoryName", entity.CategoryName);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #5
0
 public void Add(Book entity)
 {
     using (SqlCommand cmd =
                new SqlCommand("INSERT INTO Books (Title,Description, Price, CategoryId) VALUES (@Title,@Description, @Price, @CategoryId)"))
     {
         cmd.Parameters.AddWithValue("Title", entity.Title);
         cmd.Parameters.AddWithValue("Description", entity.Description);
         cmd.Parameters.AddWithValue("Price", entity.Price);
         cmd.Parameters.AddWithValue("CategoryId", entity.CategoryId);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #6
0
 public void Update(Book entity)
 {
     using (SqlCommand cmd =
                new SqlCommand("UPDATE Books set Title = @Title, Description = @Description, Price = @Price, CategoryId = @CategoryId where Id = @Id"))
     {
         cmd.Parameters.AddWithValue("Id", entity.Id);
         cmd.Parameters.AddWithValue("Title", entity.Title);
         cmd.Parameters.AddWithValue("Description", entity.Description);
         cmd.Parameters.AddWithValue("Price", entity.Price);
         cmd.Parameters.AddWithValue("CategoryId", entity.CategoryId);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }