public static bool DeleteProduct(string productParam) { using (test_productEntities db = new test_productEntities()) { ProductsTable ProductChose = db.ProductsTables.FirstOrDefault(a => a.ProductName == productParam); if (ProductChose == null) { return(false); } db.ProductsTables.Remove(ProductChose); db.SaveChanges(); return(true); } }
public static Product GetSpeseficProduct(string productParam) { using (test_productEntities db = new test_productEntities()) { ProductsTable ProductChose = db.ProductsTables.FirstOrDefault(a => a.ProductName == productParam); if (ProductChose == null) { return(null); } return(new Product { ProductName = ProductChose.ProductName, Price = ProductChose.ProductPrice }); } }
public static bool EditProduct(string productname, Product Productparam) { try { using (test_productEntities db = new test_productEntities()) { ProductsTable SelectedProuduct = db.ProductsTables.FirstOrDefault(a => a.ProductName == Productparam.ProductName); if (SelectedProuduct == null) { return(false); } SelectedProuduct.ProductPrice = Productparam.Price; db.SaveChanges(); return(true); } } catch { return(false); } }
public static bool AddProduct(Product Productparam) { try { using (test_productEntities db = new test_productEntities()) { ProductsTable NewProduct = new ProductsTable { ProductName = Productparam.ProductName, ProductPrice = Productparam.Price, }; db.ProductsTables.Add(NewProduct); db.SaveChanges(); return(true); } } catch { return(false); } }