コード例 #1
0
        public HttpResponseMessage Post(Products value, int id)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }
            int action = 0;

            if (id == 1)
            {
                action = Constants.ACTION_ADD;
            }
            else
            {
                action = Constants.ACTION_EDIT;
            }
            int check = new SessionHelper().checkSession(Constants.USERS, action);

            if (check > 0)
            {
                bool          resultQuery = false;
                ProductsModel model       = new ProductsModel();
                if (id == 1)
                {
                    resultQuery = model.insert(value);
                }
                else
                {
                    resultQuery = model.update(value);
                }
                if (resultQuery)
                {
                    string message   = (id == 1)?Constants.INSERT_SUCCESS:Constants.UPDATE_SUCCESS;
                    var    exception = JObject.FromObject(new { err = Constants.PROCESS_OK, msg = message });
                    return(Request.CreateResponse(HttpStatusCode.OK, exception));
                }
                else
                {
                    string  message   = (id == 1)?Constants.INSERT_FAIL:Constants.UPDATE_FAIL;
                    JObject exception = JObject.FromObject(new { err = Constants.PROCESS_FAILED, msg = message });
                    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));
            }
        }