Exemplo n.º 1
0
    public Product GetProduct(int id)
    {
        try {
            using (CustProductEntities db = new CustProductEntities())
            {
                Product product = db.Products.Find(id);
                return(product);
            }
        }

        catch (Exception)
        {
            return(null);
        }
    }
Exemplo n.º 2
0
    public string AddProduct(Product product)
    {
        try
        {
            CustProductEntities db = new CustProductEntities();
            db.Products.Add(product);
            db.SaveChanges();

            return(product.ProductName + " was successfully added ");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
Exemplo n.º 3
0
    public List <Product> GetitemsByCategory(string categoryname)
    {
        try
        {
            using (CustProductEntities db = new CustProductEntities())
            {
                List <Product> Items = (from x in db.Products where x.ProductCategory == categoryname select x).ToList();
                return(Items);
            }
        }

        catch (Exception)
        {
            return(null);
        }
    }
Exemplo n.º 4
0
    public List <Product> GetAllProducts()
    {
        try
        {
            using (CustProductEntities db = new CustProductEntities())
            {
                List <Product> products = (from x in db.Products select x).ToList();
                return(products);
            }
        }

        catch (Exception)
        {
            return(null);
        }
    }