public void Add(Category entity) { using (SqlCommand cmd = new SqlCommand("INSERT INTO Categories VALUES (@CategoryName)")) { cmd.Parameters.AddWithValue("CategoryName", entity.CategoryName); VTYS.SqlExecuteNonQuery(cmd); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); }
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); }
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); }
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); }