public JsonResult GetPetTypes() { List <TPetType> all = null; using (Entities1 dc = new Entities1()) { dc.Configuration.ProxyCreationEnabled = false; var petType = from a in dc.TPetTypes select new { a }; if (petType != null) { all = new List <TPetType>(); foreach (var i in petType) { TPetType con = i.a; all.Add(con); } } } return(new JsonResult { Data = all, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
//Get Service Type by ID public TPetType GetPetType(int intPetTypeID) { TPetType petType = null; using (Entities1 dc = new Entities1()) { var v = (from a in dc.TPetTypes where a.intPetTypeID.Equals(intPetTypeID) select new { a }).FirstOrDefault(); if (v != null) { petType = v.a; } return(petType); } }
public ActionResult Save(TPetType c) { string message = ""; bool status = false; if (ModelState.IsValid) { using (Entities1 dc = new Entities1()) { if (c.intPetTypeID > 0) { var v = dc.TPetTypes.Where(a => a.intPetTypeID.Equals(c.intPetTypeID)).FirstOrDefault(); if (v != null) { v.strPetType = c.strPetType; } else { return(HttpNotFound()); } } else { dc.TPetTypes.Add(c); } dc.SaveChanges(); status = true; message = "Data Is Successfully Saved."; } } else { message = "Error! Please try again."; } return(new JsonResult { Data = new { status = status, message = message } }); }