public HttpResponseMessage Post(InstancearchiveWrap instancearchiveWrap) { string errMsg = ""; string errMsgForChangeset = ""; bool isChangesetError = false; Instancearchive model = instancearchiveWrap.Instancearchive; Model.Changeset changeset = new Model.Changeset(); try { string token = this.ControllerContext.Request.Headers.GetValues("Token").First(); auth = TokenManage.GetAuthorizer(token, out errMsg); //bool isChecked = TokenManage.CheckAuthorizer(token, PowerStatusCode.Manager, out auth, out errMsg); //车辆审核人及车辆管理员都可以归档车辆申请单 if (auth.IsChecker || auth.IsManager) { if (tryValidate(model, out errMsg)) { if (this.tryPost(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 = ""; if (errMsg.Length > 0) { status = (HttpStatusCode)422; var msg = new { errors = new { ServerSideError = errMsg } }; json = JsonConvert.SerializeObject(msg); } else { model.Id = 1; status = HttpStatusCode.OK; var msg = new { Instancearchive = 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") }); }
public HttpResponseMessage Post(OptimizerWrap optimizerWrap) { string errMsg = ""; string errMsgForChangeset = ""; bool isChangesetError = false; Optimizer model = optimizerWrap.Optimizer; Model.Changeset changeset = new Model.Changeset(); try { string token = this.ControllerContext.Request.Headers.GetValues("Token").First(); auth = TokenManage.GetAuthorizer(token, out errMsg); //非扫码权限拥有者才可执行该功能 bool isChecked = auth.IsAuthorized && !auth.IsScanner; if (isChecked) { if (tryValidate(model, out errMsg)) { if (this.tryPost(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 = ""; if (errMsg.Length > 0) { status = (HttpStatusCode)422; var msg = new { errors = new { ServerSideError = errMsg } }; json = JsonConvert.SerializeObject(msg); } else { model.Id = 1; status = HttpStatusCode.OK; var msg = new { Optimizer = 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") }); }
public HttpResponseMessage Put(int id, UserWrap userWrap) { string errMsg = ""; string errMsgForChangeset = ""; bool isChangesetError = false; User model = userWrap.User; model.Id = id; Model.Changeset changeset = new Model.Changeset(); try { string token = this.ControllerContext.Request.Headers.GetValues("Token").First(); auth = TokenManage.GetAuthorizer(token, out errMsg); bool isChecked = false; if (auth.IsAuthorized && auth.UserId == model.Id) { //自己修改自己的账户信息 isChecked = true; } else if (auth.IsAuthorized && TokenManage.CheckAuthorizer(auth, PowerStatusCode.Systemer, out errMsg)) { isChecked = true; } 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 = ""; 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 { User = 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") }); }