public ActionResult Delete(int id) { using (agriviDBEntities db = new agriviDBEntities()) { Spojevi compound = db.Spojevi.Where(x => x.idSpoja == id).FirstOrDefault <Spojevi>(); db.Spojevi.Remove(compound); db.SaveChanges(); return(Json(new { succes = true, message = "Deleted!", JsonRequestBehavior.AllowGet })); } }
public ActionResult AddOrEdit(Spojevi compound) { using (agriviDBEntities db = new agriviDBEntities()) { if (compound.idSpoja == 0) { List <Spojevi> list = db.Spojevi.ToList <Spojevi>(); if (list.Count > 0) { compound.idSpoja = list.Last().idSpoja + 1; } db.Spojevi.Add(compound); db.SaveChanges(); return(Json(new { success = true, message = "Added!", JsonRequestBehavior.AllowGet })); } else { db.Entry(compound).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated!", JsonRequestBehavior.AllowGet })); } } }