コード例 #1
0
        // POST: api/Parent
        public HttpResponseMessage Post([FromBody] Parent ts)
        {
            IEnumerable <Parent> key = null;
            string msg = "";

            try
            {
                if (ts == null)
                {
                    throw new Exception("Task cannot be null");
                }
                else
                {
                    key = new ParentBusiness(parentcontext).Post(ts);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var response = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content      = new StringContent(string.Format(msg)),
                    ReasonPhrase = "Error"
                };
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.Created, key));
        }
コード例 #2
0
        // GET: api/Parent/5
        public HttpResponseMessage Get(int id)
        {
            IEnumerable <Parent> dt = null;

            try
            {
                if (id < 0)
                {
                    throw new Exception("Task cannot be null");
                }
                else
                {
                    dt = new ParentBusiness(parentcontext).GetParents(id);
                }
            }
            catch (Exception ex)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(string.Format(ex.Message)),
                    ReasonPhrase = "Error"
                };
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.OK, dt));
        }
コード例 #3
0
        // DELETE: api/Parent/5
        public HttpResponseMessage Delete(int id)
        {
            string msg = "";
            int    key = 0;
            HttpResponseMessage response;

            try
            {
                if (id <= 0)
                {
                    throw new Exception("Parameter cannot be null");
                }
                else
                {
                    key = new ParentBusiness(parentcontext).Delete(id);
                }
            }
            catch (Exception ex)
            {
                msg      = ex.Message;
                response = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content      = new StringContent(string.Format(msg)),
                    ReasonPhrase = "Error"
                };
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.OK, key));
        }
コード例 #4
0
        // PUT: api/Parent/5
        public HttpResponseMessage Put(int id, [FromBody] Parent ts)
        {
            string msg = "";
            IEnumerable <Parent> key = null;
            HttpResponseMessage  response;

            try
            {
                if ((ts == null) || (id <= 0))
                {
                    throw new Exception("Parameter cannot be null");
                }
                else
                {
                    key = new ParentBusiness(parentcontext).Put(ts);
                }
            }
            catch (Exception ex)
            {
                msg      = ex.Message;
                response = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content      = new StringContent(string.Format(msg)),
                    ReasonPhrase = "Error"
                };
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.Created, key));
        }
コード例 #5
0
        // GET: api/Parent
        public HttpResponseMessage Get()
        {
            IEnumerable <Parent> dt = null;

            try
            {
                dt = new ParentBusiness(parentcontext).GetParents();
            }
            catch (Exception ex)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(string.Format(ex.Message)),
                    ReasonPhrase = "Error"
                };
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.OK, dt));
        }
コード例 #6
0
        public HttpResponseMessage Delete([FromBody] Parent ts)
        {
            string msg = "";
            int    key = 0;

            try
            {
                key = new ParentBusiness().Delete(ts);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var response = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content      = new StringContent(string.Format(msg)),
                    ReasonPhrase = "Error"
                };
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.OK, key));;
        }
コード例 #7
0
        // POST: api/Parent
        public HttpResponseMessage Post([FromBody] Parent ts)
        {
            IEnumerable <Parent> key = null;
            string msg = "";

            try
            {
                key = new ParentBusiness().PostTaskById(ts);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var response = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content      = new StringContent(string.Format(msg)),
                    ReasonPhrase = "Error"
                };
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.Created, key));
        }
コード例 #8
0
        // GET: api/Parent/5
        public HttpResponseMessage Get(int id)
        {
            string msg = "";
            IEnumerable <Parent> dt = null;

            try
            {
                dt = new ParentBusiness().GetParentTasksById(id);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(string.Format(msg)),
                    ReasonPhrase = "Error"
                };
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.OK, dt));
        }