public Category1 GetCategory(int id)
 {
     using (ProductsDBEntities dbContext = new ProductsDBEntities())
     {
         return(dbContext.Categories.FirstOrDefault(e => e.ID == id));
     }
 }
Ejemplo n.º 2
0
 public JsonResult AddProduct(string newProduct, string newProductPrice, string newProductType)
 {
     try
     {
         var db = new ProductsDBEntities();
         db.Products.Add(new Product()
         {
             ProductName = newProduct, Price = float.Parse(newProductPrice), ProductType = newProductType
         });
         db.SaveChanges();
         var products = db.Products.ToList();
         return(Json(products, JsonRequestBehavior.AllowGet));
     }
     catch (DbEntityValidationException e)
     {
         //foreach (var eve in e.EntityValidationErrors)
         //{
         //    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
         //        eve.Entry.Entity.GetType().Name, eve.Entry.State);
         //    foreach (var ve in eve.ValidationErrors)
         //    {
         //       Debug.WriteLine ("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
         //        ve.PropertyName,
         //            eve.Entry.CurrentValues.GetValue<object>(ve.PropertyName),
         //            ve.ErrorMessage);
         //    }
         //}
         throw e;
     }
 }
 public IEnumerable <Category1> GetCategories()
 {
     using (ProductsDBEntities entities = new ProductsDBEntities())
     {
         return(entities.Categories.ToList());
     }
 }
 public Products1 GetProduct(int id)
 {
     using (ProductsDBEntities dbContext = new ProductsDBEntities())
     {
         return(dbContext.Products.FirstOrDefault(e => e.ID == id));
     }
 }
 public IEnumerable <Products1> GetProducts()
 {
     using (ProductsDBEntities entities = new ProductsDBEntities())
     {
         return(entities.Products.ToList());
     }
 }
Ejemplo n.º 6
0
        public IQueryable <Detailproduct> getDetail(ProductsDBEntities db)
        {
            //IQueryable<Detailproduct> res = db.Detailproducts.Where(x => x.Vendor.Contains("a"));
            IQueryable <Detailproduct> res = db.Detailproducts.OrderBy(x => x.Price);

            return(res);
        }
 public void DeleteCategory(int id)
 {
     using (ProductsDBEntities dbContext = new ProductsDBEntities())
     {
         dbContext.Categories.Remove(dbContext.Categories.FirstOrDefault(e => e.ID == id));
         dbContext.SaveChanges();
     }
 }
 public void PostCategory([FromBody] Category1 category)
 {
     using (ProductsDBEntities dbContext = new ProductsDBEntities())
     {
         dbContext.Categories.Add(category);
         dbContext.SaveChanges();
     }
 }
 public void PostProduct([FromBody] Products1 product)
 {
     using (ProductsDBEntities dbContext = new ProductsDBEntities())
     {
         dbContext.Products.Add(product);
         dbContext.SaveChanges();
     }
 }
 public void PutCategory(int id, [FromBody] Category1 category)
 {
     using (ProductsDBEntities dbContext = new ProductsDBEntities())
     {
         var entity = dbContext.Categories.FirstOrDefault(e => e.ID == id);
         entity.Name = category.Name;
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 11
0
        public JsonResult DeleteProduct(Product delProduct)
        {
            var db      = new ProductsDBEntities();
            var product = db.Products.Find(delProduct.Id);

            db.Products.Remove(product);
            db.SaveChanges();
            var products = db.Products.ToList();

            return(Json(products, JsonRequestBehavior.AllowGet));
        }
 public void PutProduct(int id, [FromBody] Products1 product)
 {
     using (ProductsDBEntities dbContext = new ProductsDBEntities())
     {
         var entity = dbContext.Products.FirstOrDefault(e => e.ID == id);
         entity.Name        = product.Name;
         entity.Price       = product.Price;
         entity.Category_Id = product.Category_Id;
         dbContext.SaveChanges();
     }
 }