コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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));
        }