public ItemGioHang(int id) { using (LIMUPAStoreEntities db = new LIMUPAStoreEntities()) { this.MaSP = id; PRODUCT product = db.PRODUCTs.Single(s => s.PRODUCT_ID == id); TenSP = product.PRODUCT_NAME; HinhAnh = product.PRODUCT_IMAGE; DonGia = (decimal)product.PRICE; SoLuong = 1; ThanhTien = DonGia * SoLuong; } }
public static void AddProduct(PRODUCT product) { string query = "INSERT INTO PRODUCTS(Name, Description, Stock) " + "VALUES(@Name,@Description,@Stock)"; try { using (var connection = new SqlConnection(connectionString)) { var command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@Name", product.Name); command.Parameters.AddWithValue("@Description", product.Description); command.Parameters.AddWithValue("@Stock", product.Stock); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } catch (Exception) { } }