public IHttpActionResult Get(int id) { var b = new News_TypeDAO().Take(id); // Lay phan tu voi id tuong ung if (b == null) { return(NotFound()); } return(Ok(b)); }
public IHttpActionResult Post([FromUri] JObject jsonResult) { if (!ModelState.IsValid) // Kiem tra tinh hop le cua giu lieu { return(BadRequest(ModelState)); } var x = JsonConvert.DeserializeObject <News_TypeDTO>(jsonResult.ToString()); var last = new News_TypeDAO().Add(x); return(Ok(last)); }
public IHttpActionResult Delete(int id) { var dao = new News_TypeDAO(); if (!dao.isExist(id)) // Kiem tra xem id co hop le hay khong { return(NotFound()); } var check = dao.Delete(id); // Kiem tra viec thuc hien Delete return(Ok(check)); }
public IHttpActionResult Put([FromBody] JObject jsonResult) { if (!ModelState.IsValid) // Kiem tra tinh hop le cua giu lieu { return(BadRequest(ModelState)); } var x = JsonConvert.DeserializeObject <News_TypeDTO>(jsonResult.ToString()); // Ep kieu Json sang DTO var dao = new News_TypeDAO(); if (!dao.isExist(x.ID)) // Kiem tra id co hop le khong { return(NotFound()); } dao.Update(x); // Cap nhat return(Ok()); }
public IHttpActionResult GetAllUsers(int?number) { IEnumerable <News_TypeDTO> ls; if (number == null) { ls = new News_TypeDAO().List(); } else { ls = new News_TypeDAO().List().Take((int)number); } if (ls == null) { return(NotFound()); } return(Ok(ls)); }