public JsonResult GetVisitReasons() { List <TVisitReason> all = null; using (Entities1 dc = new Entities1()) { dc.Configuration.ProxyCreationEnabled = false; var visitReason = from a in dc.TVisitReasons select new { a }; if (visitReason != null) { all = new List <TVisitReason>(); foreach (var i in visitReason) { TVisitReason con = i.a; all.Add(con); } } } return(new JsonResult { Data = all, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
// Get VisitReason by ID public TVisitReason GetVisitReason(int intVisitReasonID) { TVisitReason visitReason = null; using (Entities1 dc = new Entities1()) { var v = (from a in dc.TVisitReasons where a.intVisitReasonID.Equals(intVisitReasonID) select new { a }).FirstOrDefault(); if (v != null) { visitReason = v.a; } return(visitReason); } }
public ActionResult Update(TVisitReason c) { string message = ""; bool status = false; if (ModelState.IsValid) { using (Entities1 dc = new Entities1()) { if (c.intVisitReasonID > 0) { var v = dc.TVisitReasons.Where(a => a.intVisitReasonID.Equals(c.intVisitReasonID)).FirstOrDefault(); if (v != null) { v.strVisitReason = c.strVisitReason; } else { return(HttpNotFound()); } } else { dc.TVisitReasons.Add(c); } dc.SaveChanges(); status = true; message = "Data Is Successfully Updated."; } } else { message = "Error! Please try again."; } return(new JsonResult { Data = new { status = status, message = message } }); }