public JsonResult getAll()
 {
     using (ProductsDbEntities dataContext = new ProductsDbEntities())
     {
         var productList = dataContext.Products.ToList();
         return(Json(productList, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult IndexVM()
 {
     using (ProductsDbEntities dataContext = new ProductsDbEntities())
     {
         var employeeList = dataContext.Products.ToList();
         return(Json(employeeList, JsonRequestBehavior.AllowGet));
     }
 }
 public JsonResult getProductByNo(string ProdNo)
 {
     using (ProductsDbEntities dataContext = new ProductsDbEntities())
     {
         int no          = Convert.ToInt32(ProdNo);
         var productList = dataContext.Products.Find(no);
         return(Json(productList, JsonRequestBehavior.AllowGet));
     }
 }
Пример #4
0
        public TblOrder Add(TblOrder item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            // TO DO : Code to save record into database
            ProductsDbEntities OrderDb = new ProductsDbEntities();

            OrderDb.TblOrders.Add(item);
            OrderDb.SaveChanges();
            return(item);
        }
 public string AddEmployee(Product Emp)
 {
     if (Emp != null)
     {
         using (ProductsDbEntities dataContext = new ProductsDbEntities())
         {
             dataContext.Products.Add(Emp);
             dataContext.SaveChanges();
             return("Employee Updated");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }
 public string DeleteEmployee(Product Emp)
 {
     if (Emp != null)
     {
         using (ProductsDbEntities dataContext = new ProductsDbEntities())
         {
             int no           = Convert.ToInt32(Emp.Id);
             var employeeList = dataContext.Products.Where(x => x.Id == no).FirstOrDefault();
             dataContext.Products.Remove(employeeList);
             dataContext.SaveChanges();
             return("Employee Deleted");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }
        public string UpdateEmployee(Product Prod)
        {
            if (Prod != null)
            {
                using (ProductsDbEntities dataContext = new ProductsDbEntities())
                {
                    int no          = Convert.ToInt32(Prod.Id);
                    var productList = dataContext.Products.Where(x => x.Id == no).FirstOrDefault();
                    productList.Name        = Prod.Name;
                    productList.Price       = Prod.Price;
                    productList.Description = Prod.Description;
                    productList.Image       = Prod.Image;

                    dataContext.SaveChanges();
                    return("Employee Updated");
                }
            }
            else
            {
                return("Invalid Employee");
            }
        }