// DELETE api/<controller>/5 public void Delete(int id) { KenhTinBaiViet obj = db.KenhTinBaiViets.Where(o => o.Id == id).SingleOrDefault(); db.KenhTinBaiViets.DeleteOnSubmit(obj); db.SubmitChanges(); }
// PUT api/<controller>/5 public void Put(int id, [FromBody] KenhTinBaiViet value) { KenhTinBaiViet obj = db.KenhTinBaiViets.Where(o => o.Id == id).SingleOrDefault(); KenhTinBaiViet newobj = value;// JsonConvert.DeserializeObject<KenhTinBaiViet>(value); if (newobj.NoiDung != null) { obj.NoiDung = newobj.NoiDung; } if (newobj.MaCapTren != null) { obj.MaCapTren = newobj.MaCapTren; } db.SubmitChanges(); }
public IEnumerable <KenhTinBaiViet> Get() { string filter = HttpContext.Current.Request.Params.Get("filter"); if (string.IsNullOrEmpty(filter)) { List <KenhTinBaiViet> lst = (from table in db.KenhTinBaiViets select table).ToList(); return(lst); //string json = JsonConvert.SerializeObject(lst); //return new string[] { json }; } else { KenhTinBaiViet obj = JsonConvert.DeserializeObject <KenhTinBaiViet>(filter); List <KenhTinBaiViet> lst = (from table in db.KenhTinBaiViets where (obj.MaCapTren == null || obj.MaCapTren == table.MaCapTren) select table).ToList(); return(lst); //string json = JsonConvert.SerializeObject(lst); //return new string[] { json }; } }
// POST api/<controller> public void Post([FromBody] KenhTinBaiViet value) { // KenhTinBaiViet newobj = (KenhTinBaiViet)JsonConvert.DeserializeObject(value); db.KenhTinBaiViets.InsertOnSubmit(value); db.SubmitChanges(); }