public ActionResult AddOrEdit(Basketball entry) { using (BasketballEntities db = new BasketballEntities()) { var success = true; //Setting condition var message = ""; //Test logic var newList = db.Basketballs.ToList(); //creating new list to compare too var compare = from c in newList where c.Exercise == entry.Exercise && c.ExerciseDate == entry.ExerciseDate select c; //LINQ to filter what to compare if (compare.Any()) //Checking if same exercise added on same day { success = false; message = "false!"; } else //IF condition is met, add and save data entry { db.Basketballs.Add(entry); db.SaveChanges(); success = true; message = "succesful save!"; } return(Json(new { success, message }, JsonRequestBehavior.AllowGet)); } }
//**** Loading the database onto the MVC *****// public ActionResult GetData() { using (BasketballEntities db = new BasketballEntities()) { var bList = db.Basketballs.ToList(); return(Json(new { data = bList }, JsonRequestBehavior.AllowGet)); } }