Пример #1
0
 public IQueryable<Product> GetProducts([QueryString("id")] int? categoryId)
 {
     var _db = new Acme_Motors.Models.ProductContext();
     IQueryable<Product> query = _db.Products;
     if (categoryId.HasValue && categoryId > 0)
     {
         query = query.Where(p => p.CategoryID == categoryId);
     }
     return query;
 }
Пример #2
0
        public void addVehicleForm_InsertItem()
        {
            var item = new Models.Product();
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                using (ProductContext db = new ProductContext())
                {
                    db.Products.Add(item);
                    db.SaveChanges();
                }

            }
        }
Пример #3
0
        public IQueryable<Product> GetProduct([QueryString("productID")] int? productId)
        {
            var _db = new Acme_Motors.Models.ProductContext();
            IQueryable<Product> query = _db.Products;
            if (productId.HasValue && productId > 0)
            {
                query = query.Where(p => p.ProductID == productId);
            }
            else
            {
                query = null;
            }

            return query;
        }
Пример #4
0
 // The id parameter name should match the DataKeyNames value set on the control
 public void productsGrid_DeleteItem(int productID)
 {
     using (ProductContext db = new ProductContext())
     {
         var item = new Product { ProductID = productID };
         db.Entry(item).State = System.Data.Entity.EntityState.Deleted;
         try
         {
             db.SaveChanges();
         }
         catch (DbUpdateConcurrencyException)
         {
             ModelState.AddModelError("",String.Format("Item with id {0} no longer exists in the database.", productID));
         }
     }
 }
Пример #5
0
        /*public IQueryable<Product> GetProducts([Control("id")] int? categoryId)
        {
            var _db = new Acme_Motors.Models.ProductContext();
            IQueryable<Product> query = _db.Products;
            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }
            return query;
        }*/

        // The id parameter name should match the DataKeyNames value set on the control
        public void productsGrid_UpdateItem(int ProductID)
        {

            using (ProductContext db = new ProductContext())
            {
                Product item = null;
                // Load the item here, e.g. item = MyDataLayer.Find(id);
                item = db.Products.Find(ProductID);
                if (item == null)
                {
                    // The item wasn't found
                    ModelState.AddModelError("", String.Format("Item with id {0} was not found", ProductID));
                    return;
                }
                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    // Save changes here, e.g. MyDataLayer.SaveChanges();
                    db.SaveChanges();
                }
            }               
        }
Пример #6
0
 public IQueryable<Category> GetCategories()
 {
     var _db = new Acme_Motors.Models.ProductContext();
     IQueryable<Category> query = _db.Categories;
     return query;
 }