public ActionResult Edit(int ID) { Product Model = new Product(); using (DAL.EFDbContext db = new DAL.EFDbContext()) { Model = db.Products.Where(p => p.ID == ID).FirstOrDefault(); } return(View("Edit", Model)); }
public ActionResult Delete(int ID) { using (DAL.EFDbContext db = new DAL.EFDbContext()) { var m = db.Products.Where(p => p.ID == ID).FirstOrDefault(); db.Products.Remove(m); db.SaveChanges(); return(RedirectToAction("index")); } }
private List <Product> GetProduct(int pageIndex, int pageSize, ref int totalCount) { using (DAL.EFDbContext db = new DAL.EFDbContext()) { var m = db.Products.OrderBy(p => p.ID).Skip((pageIndex - 1) * pageSize).Take(pageSize); totalCount = db.Products.Count(); return(m.ToList()); //var persons = (from p in db.TestDataDBS orderby p.ID descending select p).Skip((pageIndex - 1) * pageSize).Take(pageSize); //totalCount = db.TestDataDBS.Count(); //return persons.ToList(); } }
public ActionResult Edit(Product model) { using (DAL.EFDbContext db = new DAL.EFDbContext()) { var m = db.Products.Where(p => p.ID == model.ID).FirstOrDefault(); m.Name = model.Name; m.Price = model.Price; m.Quantity = model.Quantity; db.SaveChanges(); //db.SaveChangesAsync(); } return(RedirectToAction("index", new { page = 2 })); }
private async Task <int> AddProduct(Product model) { using (DAL.EFDbContext db = new DAL.EFDbContext()) { new Func <int, bool>((a) => { if (a > 10) { return(true); } return(false); }).Invoke(10); Func <int, bool> aa = (b) => { if (b > 0) { return(true); } return(false); }; bool flag = aa(10); var m = db.Products.Add(model); //db.SaveChanges(); return(await db.SaveChangesAsync()); } }