示例#1
0
        public HttpResponseMessage Put(int id, PreferenceWrap preferenceWrap)
        {
            string     errMsg             = "";
            string     errMsgForChangeset = "";
            bool       isChangesetError   = false;
            Preference model = preferenceWrap.Preference;

            model.Id = id;
            Model.Changeset changeset = new Model.Changeset();
            try
            {
                string token     = this.ControllerContext.Request.Headers.GetValues("Token").First();
                bool   isChecked = TokenManage.CheckAuthorizer(token, PowerStatusCode.Systemer, out auth, out errMsg);
                if (isChecked)
                {
                    if (tryValidate(model, out errMsg))
                    {
                        if (this.tryPut(ref model, out errMsg))
                        {
                            if (!ChangesetManager.tryFetch(auth.Sync, ref changeset, out errMsgForChangeset))
                            {
                                isChangesetError = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            var    status = HttpStatusCode.OK;
            string json   = "";

            //errMsg = "网络。。。 ";
            if (errMsg.Length > 0)
            {
                status = (HttpStatusCode)422;
                var msg = new { errors = new { ServerSideError = errMsg } };
                json = JsonConvert.SerializeObject(msg);
            }
            else
            {
                status = HttpStatusCode.OK;
                var msg = new { Preference = model, Changeset = changeset, IsChangesetError = isChangesetError, ErrMsgForChangeset = errMsgForChangeset };
                json = JsonConvert.SerializeObject(msg);
            }
            return(new HttpResponseMessage(status)
            {
                Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
示例#2
0
        public HttpResponseMessage Delete(int id)
        {
            string errMsg = "";

            try
            {
                string token     = this.ControllerContext.Request.Headers.GetValues("Token").First();
                bool   isChecked = TokenManage.CheckAuthorizer(token, PowerStatusCode.Scanner, out auth, out errMsg);
                if (isChecked)
                {
                    if (id > 0)
                    {
                        this.tryDelete(id.ToString(), out errMsg);
                    }
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            var    status = HttpStatusCode.OK;
            string json   = "";

            if (errMsg.Length > 0)
            {
                status = (HttpStatusCode)422;
                var msg = new { errors = new { ServerSideError = errMsg } };
                json = JsonConvert.SerializeObject(msg);
            }
            else
            {
                status = HttpStatusCode.OK;
                var msg = new { };
                json = JsonConvert.SerializeObject(msg);
            }
            return(new HttpResponseMessage(status)
            {
                Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
示例#3
0
        public HttpResponseMessage Get()
        {
            string errMsg = "";

            Model.Startup startup = new Model.Startup();
            try
            {
                string token = this.ControllerContext.Request.Headers.GetValues("Token").First();
                if (TokenManage.CheckAuthorizer(token, PowerStatusCode.None, out errMsg))
                {
                    StartupManager.tryFetch(ref startup, out errMsg);
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            var    status = HttpStatusCode.OK;
            string json   = "";

            if (errMsg.Length > 0)
            {
                status = (HttpStatusCode)422;
                var msg = new { errors = new { ServerSideError = errMsg } };
                json = JsonConvert.SerializeObject(msg);
            }
            else
            {
                status = HttpStatusCode.OK;
                var msg = new { Startup = startup };
                json = JsonConvert.SerializeObject(msg);
            }
            return(new HttpResponseMessage(status)
            {
                Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
示例#4
0
        public HttpResponseMessage Post(SignatureWrap signatureWrap)
        {
            string    errMsg             = "";
            string    errMsgForChangeset = "";
            bool      isChangesetError   = false;
            Signature model     = signatureWrap.Signature;
            Changeset changeset = new Changeset();

            try
            {
                string token     = base.ControllerContext.Request.Headers.GetValues("Token").First <string>();
                bool   isChecked = TokenManage.CheckAuthorizer(token, PowerStatusCode.Scanner, out this.auth, out errMsg);
                if (isChecked)
                {
                    if (this.tryValidate(model, out errMsg))
                    {
                        if (this.tryPost(ref model, out errMsg))
                        {
                            if (!ChangesetManager.tryFetch(this.auth.Sync, ref changeset, out errMsgForChangeset))
                            {
                                isChangesetError = true;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                errMsg = ex.Message;
            }
            HttpStatusCode status;
            string         json;

            if (errMsg.Length > 0)
            {
                status = (HttpStatusCode)422;
                var msg = new
                {
                    errors = new
                    {
                        ServerSideError = errMsg
                    }
                };
                json = JsonConvert.SerializeObject(msg);
            }
            else
            {
                status = HttpStatusCode.OK;
                var msg2 = new
                {
                    Signature          = model,
                    Changeset          = changeset,
                    IsChangesetError   = isChangesetError,
                    ErrMsgForChangeset = errMsgForChangeset
                };
                json = JsonConvert.SerializeObject(msg2);
            }
            return(new HttpResponseMessage(status)
            {
                Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
示例#5
0
        public HttpResponseMessage Post(AccountpwdWrap accountpwdWrap)
        {
            string     errMsg             = "";
            string     errMsgForChangeset = "";
            bool       isChangesetError   = false;
            Accountpwd accountpwd         = accountpwdWrap.Accountpwd;

            Model.Changeset changeset = new Model.Changeset();
            try
            {
                string token     = this.ControllerContext.Request.Headers.GetValues("Token").First();
                bool   isChecked = false;
                if (TokenManage.CheckAuthorizer(token, PowerStatusCode.None, out auth, out errMsg))
                {
                    if (auth.UserId == accountpwd.User)
                    {
                        isChecked = true;
                    }
                    else
                    {
                        errMsg = "密码不能被本人以外其他用户修改";
                    }
                }
                if (isChecked)
                {
                    if (tryValidate(accountpwd, out errMsg))
                    {
                        if (this.tryPost(ref accountpwd, out errMsg))
                        {
                            if (!ChangesetManager.tryFetch(auth.Sync, ref changeset, out errMsgForChangeset))
                            {
                                isChangesetError = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            var    status = HttpStatusCode.OK;
            string json   = "";

            if (errMsg.Length > 0)
            {
                status = (HttpStatusCode)422;
                var msg = new { errors = new { ServerSideError = errMsg } };
                json = JsonConvert.SerializeObject(msg);
            }
            else
            {
                status = HttpStatusCode.OK;
                var msg = new { Accountpwd = accountpwd, Changeset = changeset, IsChangesetError = isChangesetError, ErrMsgForChangeset = errMsgForChangeset };
                json = JsonConvert.SerializeObject(msg);
            }
            return(new HttpResponseMessage(status)
            {
                Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }