public static string AddOrEdit(Proizvod proiz) { using (ZadatakDBEntities db = new ZadatakDBEntities()) { try { if (proiz.id == 0) { db.Proizvods.Add(proiz); db.SaveChanges(); return("Saved Successfully"); } else { db.Entry(proiz).State = EntityState.Modified; db.SaveChanges(); return("Updated Successfully"); } } catch (Exception ex) { return(ex.Message); } } }
public ActionResult GetData() { using (ZadatakDBEntities db = new ZadatakDBEntities()) { List <Proizvod> proizList = db.Proizvods.ToList(); return(Json(new { data = proizList }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Delete(int id) { using (ZadatakDBEntities db = new ZadatakDBEntities()) { Proizvod proiz = db.Proizvods.Where(x => x.id == id).FirstOrDefault(); db.Proizvods.Remove(proiz); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddOrEdit(int id = 0) { if (id == 0) { return(View(new Proizvod())); } else { using (ZadatakDBEntities db = new ZadatakDBEntities()) { return(View(db.Proizvods.Where(x => x.id == id).FirstOrDefault())); } } }
public static Proizvod AddOrEdit(int id) { if (id == 0) { return(new Proizvod()); } else { using (ZadatakDBEntities db = new ZadatakDBEntities()) { return(db.Proizvods.Where(x => x.id == id).FirstOrDefault()); } } }
public static List <Proizvod> GetData() { try { using (ZadatakDBEntities db = new ZadatakDBEntities()) { proizList = db.Proizvods.ToList(); return(proizList); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(null); } }
public static string Delete(int id) { using (ZadatakDBEntities db = new ZadatakDBEntities()) { try { Proizvod proiz = db.Proizvods.Where(x => x.id == id).FirstOrDefault(); db.Proizvods.Remove(proiz); db.SaveChanges(); return("Deleted Successfully"); } catch (Exception ex) { return(ex.Message); } } }
public ActionResult AddOrEdit(Proizvod proiz) { using (ZadatakDBEntities db = new ZadatakDBEntities()) { if (proiz.id == 0) { db.Proizvods.Add(proiz); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(proiz).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } } }