public JsonResult Edit(Store store) { using (CruddataModel1Entities db = new CruddataModel1Entities()) { if (ModelState.IsValid) { try { db.Entry(store).State = EntityState.Modified; db.SaveChanges(); } catch (DbUpdateConcurrencyException) { var result = db.Stores.SingleOrDefault(a => a.Id == store.Id); if (result == null) { return(Json(new { success = false, message = "Cannot find customer to update" }, JsonRequestBehavior.AllowGet)); } else { throw; } } return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } } return(Json(new { success = false, message = "Invalid customer given" }, JsonRequestBehavior.AllowGet)); }
public JsonResult GetProductData() { using (CruddataModel1Entities dbmodel = new CruddataModel1Entities()) { var product = dbmodel.Products.ToList(); return(Json(product, JsonRequestBehavior.AllowGet)); //return Json(new { success = true, data = customer }); } }
public JsonResult GetStoreData() { using (CruddataModel1Entities dbmodel = new CruddataModel1Entities()) { var store = dbmodel.Stores.ToList(); return(Json(store, JsonRequestBehavior.AllowGet)); //return Json(new { success = true, data = customer }); } }
public JsonResult Create(Product product) { using (CruddataModel1Entities dbmodel = new CruddataModel1Entities()) { if (ModelState.IsValid) { var data = dbmodel.Products.Add(product); dbmodel.SaveChanges(); return(Json(new { success = true, data = product })); } return(Json(new { success = false, message = "Invalid customer given" })); } }
// POST: Customer/Edit/ //[HttpPut] public JsonResult Edit(Product product) { try { using (CruddataModel1Entities dbmodel = new CruddataModel1Entities()) { dbmodel.Entry(product).State = EntityState.Modified; dbmodel.SaveChanges(); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } } catch { return(Json(new { success = false, message = "Cannot find customer to delete" }, JsonRequestBehavior.AllowGet)); } }
//[HttpDelete] public JsonResult Delete(int Id) { try { using (CruddataModel1Entities dbmodel = new CruddataModel1Entities()) { Product product = dbmodel.Products.Find(Id); dbmodel.Products.Remove(product); dbmodel.SaveChanges(); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); //return Json(new { success = true }); } } catch { return(Json(new { success = false, message = "Cannot find customer to delete" }, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetSalesData() { using (CruddataModel1Entities dbmodel = new CruddataModel1Entities()) { var sale = dbmodel.Sales.Include("Customer") .Include("Product") .Include("Store").ToList(); var saledata = sale.Select(x => new { x.Id, CustomerName = x.Customer.Name, ProductName = x.Product.Name, StoreName = x.Store.Name, DateSold = x.DateSold.ToString("yyyy/MM/dd") }); return(Json(saledata, JsonRequestBehavior.AllowGet)); //return Json(new { success = true, data = customer }); } }