Пример #1
0
 public JsonResult getAll()
 {
     using (ProductsDbEntities dataContext = new ProductsDbEntities())
     {
         var productList = dataContext.Products.ToList();
         return Json(productList, JsonRequestBehavior.AllowGet);
     }
 }
Пример #2
0
 public ActionResult IndexVM()
 {
     using (ProductsDbEntities dataContext = new ProductsDbEntities())
     {
         var employeeList = dataContext.Products.ToList();
         return Json(employeeList, JsonRequestBehavior.AllowGet);
     }
 }
Пример #3
0
 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 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";
     }
 }
Пример #5
0
        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";
            }
        }
Пример #6
0
 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";
     }
 }