コード例 #1
0
        public HttpResponseMessage GetById(int id)
        {
            int check = new SessionHelper().checkSession(Constants.USERS, Constants.ACTION_VIEW);

            if (check > 0)
            {
                ProductsModel model       = new ProductsModel();
                var           resultQuery = model.GetById(id);
                if (resultQuery != null)
                {
                    JObject result    = JObject.FromObject(resultQuery);
                    var     exception = JObject.FromObject(new { err = Constants.PROCESS_OK, data = result });
                    return(Request.CreateResponse(HttpStatusCode.OK, exception));
                }
                else
                {
                    JObject exception = JObject.FromObject(new { err = Constants.PROCESS_FAILED, msg = Constants.PROCESS_FAILED });
                    return(Request.CreateResponse(HttpStatusCode.OK, exception));
                }
            }
            else
            {
                string  message   = (check == Constants.PERMISSION_LOGIN_CODE) ? Constants.PERMISSION_LOGIN_MSG : Constants.PERMISSION_DENIED_MSG;
                JObject exception = JObject.FromObject(new { err = check, msg = message });
                return(Request.CreateResponse(HttpStatusCode.OK, exception));
            }
        }