예제 #1
0
        /// <summary>
        /// 尝试获取Changeset
        /// </summary>
        /// <returns></returns>
        public static bool tryFetch(DateTime syncToken, ref Model.Changeset model, out string errMsg)
        {
            model.Id = 1;
            TimeZone zone   = TimeZone.CurrentTimeZone;
            TimeSpan offset = zone.GetUtcOffset(DateTime.Now);

            model.SyncToken = DateTime.UtcNow.AddHours(offset.TotalHours);
            return(GetChangeset(syncToken, ref model, out errMsg));
        }
        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")
            });
        }
예제 #3
0
        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")
            });
        }
예제 #4
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")
            });
        }
예제 #5
0
        public HttpResponseMessage Get()
        {
            string errMsg = "";

            Model.Changeset changeset = new Model.Changeset();
            try
            {
                string token = this.ControllerContext.Request.Headers.GetValues("Token").First();
                if (TokenManage.CheckAuthorizer(token, PowerStatusCode.None, out auth, out errMsg))
                {
                    ChangesetManager.tryFetch(auth.Sync, ref changeset, 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 { Changeset = changeset };
                json = JsonConvert.SerializeObject(msg);
            }
            return(new HttpResponseMessage(status)
            {
                Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
예제 #6
0
        /// <summary>
        /// 获取Changeset
        /// </summary>
        /// <returns></returns>
        public static bool GetChangeset(
            DateTime syncToken,
            ref Model.Changeset model,
            out string errMsg)
        {
            IList <Model.User>       listUsers       = new List <Model.User>();
            IList <Model.Role>       listRoles       = new List <Model.Role>();
            IList <Model.Project>    listProjects    = new List <Model.Project>();
            IList <Model.Department> listDepartments = new List <Model.Department>();
            IList <Model.Oil>        listOils        = new List <Model.Oil>();
            IList <Model.Preference> listPreferences = new List <Model.Preference>();
            IList <Model.Car>        listCars        = new List <Model.Car>();
            IList <Model.Instance>   listInstances   = new List <Model.Instance>();
            IList <Model.Trace>      listTraces      = new List <Model.Trace>();
            IList <Model.Bill>       listBills       = new List <Model.Bill>();
            IList <Model.Piece>      listPieces      = new List <Model.Piece>();
            //IList<Model.Signature> listSignatures = new List<Model.Signature>();
            //IList<Model.Message> listMessages = new List<Model.Message>();
            IList <Model.Deleted> listDeleteds = new List <Model.Deleted>();

            errMsg = "";
            bool result;

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@SyncToken", syncToken)
                };
                DataSet   ds      = DBHelper.ExecuteGetDataSet(CommandType.StoredProcedure, "proc_ChangesetSelect", "User,Role,Project,Department,Oil,Preference,Car,Instance,Trace,Bill,Piece,Deleted", para);
                DataTable dtUsers = ds.Tables["User"];
                foreach (DataRow dr in dtUsers.Rows)
                {
                    listUsers.Add(new User
                    {
                        Id           = (int)dr["Id"],
                        Name         = (string)dr["Name"],
                        Phone        = (string)dr["Phone"],
                        Email        = (string)dr["Email"],
                        Role         = (int)dr["Role"],
                        Signature    = (string)dr["Signature"],
                        IsSignNeeded = (bool)dr["IsSignNeeded"],
                        IsEnable     = (bool)dr["IsEnable"],
                        Creater      = (int)dr["Creater"],
                        CreatedDate  = (DateTime)dr["CreatedDate"],
                        Modifier     = (int)dr["Modifier"],
                        ModifiedDate = (DateTime)dr["ModifiedDate"]
                    });
                }
                DataTable dtRoles = ds.Tables["Role"];
                foreach (DataRow dr in dtRoles.Rows)
                {
                    Role role = new Role();
                    role.Id   = (int)dr["Id"];
                    role.Name = (string)dr["Name"];
                    if (!DBNull.Value.Equals(dr["Powers"]))
                    {
                        string   powersStr   = (string)dr["Powers"];
                        string[] powersArray = powersStr.Split(new char[]
                        {
                            ','
                        });
                        IList <int> powers = new List <int>();
                        int         i      = 0;
                        int         len    = powersArray.Length;
                        while (i < len)
                        {
                            int power;
                            if (int.TryParse(powersArray[i], out power))
                            {
                                powers.Add(power);
                            }
                            i++;
                        }
                        role.Powers = powers;
                    }
                    role.Description  = (string)dr["Description"];
                    role.Creater      = (int)dr["Creater"];
                    role.CreatedDate  = (DateTime)dr["CreatedDate"];
                    role.Modifier     = (int)dr["Modifier"];
                    role.ModifiedDate = (DateTime)dr["ModifiedDate"];
                    listRoles.Add(role);
                }
                DataTable dtDepartments = ds.Tables["Department"];
                foreach (DataRow dr in dtDepartments.Rows)
                {
                    listDepartments.Add(new Department
                    {
                        Id           = (int)dr["Id"],
                        Name         = (string)dr["Name"],
                        Description  = (string)dr["Description"],
                        Creater      = (int)dr["Creater"],
                        CreatedDate  = (DateTime)dr["CreatedDate"],
                        Modifier     = (int)dr["Modifier"],
                        ModifiedDate = (DateTime)dr["ModifiedDate"]
                    });
                }
                DataTable dtProjects = ds.Tables["Project"];
                foreach (DataRow dr in dtProjects.Rows)
                {
                    listProjects.Add(new Project
                    {
                        Id           = (int)dr["Id"],
                        Name         = (string)dr["Name"],
                        IsEnable     = (bool)dr["IsEnable"],
                        Description  = (string)dr["Description"],
                        Creater      = (int)dr["Creater"],
                        CreatedDate  = (DateTime)dr["CreatedDate"],
                        Modifier     = (int)dr["Modifier"],
                        ModifiedDate = (DateTime)dr["ModifiedDate"]
                    });
                }
                DataTable dtOils = ds.Tables["Oil"];
                foreach (DataRow dr in dtOils.Rows)
                {
                    listOils.Add(new Oil
                    {
                        Id           = (int)dr["Id"],
                        Name         = (string)dr["Name"],
                        YellowRate   = double.Parse(dr["YellowRate"].ToString()),
                        RedRate      = double.Parse(dr["RedRate"].ToString()),
                        Description  = (string)dr["Description"],
                        Creater      = (int)dr["Creater"],
                        CreatedDate  = (DateTime)dr["CreatedDate"],
                        Modifier     = (int)dr["Modifier"],
                        ModifiedDate = (DateTime)dr["ModifiedDate"]
                    });
                }
                DataTable dtPreferences = ds.Tables["Preference"];
                foreach (DataRow dr in dtPreferences.Rows)
                {
                    listPreferences.Add(new Preference
                    {
                        Id           = (int)dr["Id"],
                        ShortcutHour = (int)dr["ShortcutHour"],
                        FinishHour   = (int)dr["FinishHour"],
                        Creater      = (int)dr["Creater"],
                        CreatedDate  = (DateTime)dr["CreatedDate"],
                        Modifier     = (int)dr["Modifier"],
                        ModifiedDate = (DateTime)dr["ModifiedDate"]
                    });
                }
                DataTable dtCars = ds.Tables["Car"];
                foreach (DataRow dr in dtCars.Rows)
                {
                    Car car = new Car();
                    car.Id         = (int)dr["Id"];
                    car.Number     = (string)dr["Number"];
                    car.Vin        = (string)dr["Vin"];
                    car.Model      = (string)dr["Model"];
                    car.IsArchived = (bool)dr["IsArchived"];
                    //if (!DBNull.Value.Equals(dr["Instances"]))
                    //{
                    //    string instancesStr = (string)dr["Instances"];
                    //    string[] instsArrayTemp = instancesStr.Split(new char[]
                    //    {
                    //        ','
                    //    });
                    //    int[] instsArray = Array.ConvertAll<string, int>(instsArrayTemp, (string s) => int.Parse(s));
                    //    car.Instances = instsArray.ToList<int>();
                    //}
                    car.InstanceCount = (int)dr["InstanceCount"];
                    car.BillCount     = (int)dr["BillCount"];
                    if (DBNull.Value.Equals(dr["PreviousOil"]))
                    {
                        car.PreviousOil = null;
                    }
                    else
                    {
                        car.PreviousOil = new int?((int)dr["PreviousOil"]);
                    }
                    if (DBNull.Value.Equals(dr["LastOil"]))
                    {
                        car.LastOil = null;
                    }
                    else
                    {
                        car.LastOil = new int?((int)dr["LastOil"]);
                    }
                    car.LastVolume   = (double)dr["LastVolume"];
                    car.LastMileage  = (double)dr["LastMileage"];
                    car.LastRate     = (double)dr["LastRate"];
                    car.Description  = (string)dr["Description"];
                    car.Creater      = (int)dr["Creater"];
                    car.CreatedDate  = (DateTime)dr["CreatedDate"];
                    car.Modifier     = (int)dr["Modifier"];
                    car.ModifiedDate = (DateTime)dr["ModifiedDate"];
                    listCars.Add(car);
                }
                DataTable dtInstances = ds.Tables["Instance"];
                foreach (DataRow dr in dtInstances.Rows)
                {
                    Instance instance = new Instance();
                    instance.Id         = (int)dr["Id"];
                    instance.Car        = (int)dr["Car"];
                    instance.Project    = (int)dr["Project"];
                    instance.Department = (int)dr["Department"];
                    instance.UserName   = (string)dr["UserName"];
                    if (!DBNull.Value.Equals(dr["Oils"]))
                    {
                        string   oilsStr       = (string)dr["Oils"];
                        string[] oilsArrayTemp = oilsStr.Split(new char[]
                        {
                            ','
                        });
                        int[] oilsArray = Array.ConvertAll <string, int>(oilsArrayTemp, (string s) => int.Parse(s));
                        instance.Oils = oilsArray.ToList <int>();
                    }
                    instance.Goal       = (string)dr["Goal"];
                    instance.StartDate  = (DateTime)dr["StartDate"];
                    instance.EndDate    = (DateTime)dr["EndDate"];
                    instance.IsReleased = (bool)dr["IsReleased"];
                    instance.IsPending  = (bool)dr["IsPending"];
                    instance.IsArchived = (bool)dr["IsArchived"];
                    instance.IsEnable   = (bool)dr["IsEnable"];
                    //if (DBNull.Value.Equals(dr["Message"]))
                    //{
                    //    instance.Message = null;
                    //}
                    //else
                    //{
                    //    instance.Message = new int?((int)dr["Message"]);
                    //}
                    instance.BillCount    = (int)dr["BillCount"];
                    instance.Creater      = (int)dr["Creater"];
                    instance.CreatedDate  = (DateTime)dr["CreatedDate"];
                    instance.Modifier     = (int)dr["Modifier"];
                    instance.ModifiedDate = (DateTime)dr["ModifiedDate"];
                    listInstances.Add(instance);
                }
                DataTable dtTraces = ds.Tables["Trace"];
                foreach (DataRow dr in dtTraces.Rows)
                {
                    Trace trace = new Trace();
                    trace.Id       = (int)dr["Id"];
                    trace.Car      = (int)dr["Car"];
                    trace.Instance = (int)dr["Instance"];
                    if (DBNull.Value.Equals(dr["PreviousTrace"]))
                    {
                        trace.PreviousTrace = null;
                    }
                    else
                    {
                        trace.PreviousTrace = new int?((int)dr["PreviousTrace"]);
                    }
                    trace.Status     = (string)dr["Status"];
                    trace.IsFinished = (bool)dr["IsFinished"];
                    trace.IsArchived = (bool)dr["IsArchived"];
                    trace.Project    = (int)dr["Project"];
                    trace.Department = (int)dr["Department"];
                    trace.UserName   = (string)dr["UserName"];
                    if (!DBNull.Value.Equals(dr["Oils"]))
                    {
                        string   oilsStr       = (string)dr["Oils"];
                        string[] oilsArrayTemp = oilsStr.Split(new char[]
                        {
                            ','
                        });
                        int[] oilsArray = Array.ConvertAll <string, int>(oilsArrayTemp, (string s) => int.Parse(s));
                        trace.Oils = oilsArray.ToList <int>();
                    }
                    trace.Goal         = (string)dr["Goal"];
                    trace.StartDate    = (DateTime)dr["StartDate"];
                    trace.EndDate      = (DateTime)dr["EndDate"];
                    trace.StartInfo    = (string)dr["StartInfo"];
                    trace.EndInfo      = (string)dr["EndInfo"];
                    trace.Creater      = (int)dr["Creater"];
                    trace.CreatedDate  = (DateTime)dr["CreatedDate"];
                    trace.Modifier     = (int)dr["Modifier"];
                    trace.ModifiedDate = (DateTime)dr["ModifiedDate"];
                    listTraces.Add(trace);
                }
                DataTable dtBills = ds.Tables["Bill"];
                foreach (DataRow dr in dtBills.Rows)
                {
                    Bill bill = new Bill();
                    bill.Id         = (int)dr["Id"];
                    bill.Car        = (int)dr["Car"];
                    bill.Instance   = (int)dr["Instance"];
                    bill.Project    = (int)dr["Project"];
                    bill.Department = (int)dr["Department"];
                    bill.Oil        = (int)dr["Oil"];
                    bill.Volume     = double.Parse(dr["Volume"].ToString());
                    bill.Mileage    = double.Parse(dr["Mileage"].ToString());
                    bill.DriverName = (string)dr["DriverName"];
                    if (DBNull.Value.Equals(dr["Signature"]))
                    {
                        bill.Signature = null;
                    }
                    else
                    {
                        bill.Signature = new int?((int)dr["Signature"]);
                    }
                    if (DBNull.Value.Equals(dr["PreviousOil"]))
                    {
                        bill.PreviousOil = null;
                    }
                    else
                    {
                        bill.PreviousOil = new int?((int)dr["PreviousOil"]);
                    }
                    bill.Rate         = double.Parse(dr["Rate"].ToString());
                    bill.Oiler        = (int)dr["Oiler"];
                    bill.Time         = (DateTime)dr["Time"];
                    bill.IsLost       = (bool)dr["IsLost"];
                    bill.IsPrinted    = (bool)dr["IsPrinted"];
                    bill.Creater      = (int)dr["Creater"];
                    bill.CreatedDate  = (DateTime)dr["CreatedDate"];
                    bill.Modifier     = (int)dr["Modifier"];
                    bill.ModifiedDate = (DateTime)dr["ModifiedDate"];
                    listBills.Add(bill);
                }
                DataTable dtPieces = ds.Tables["Piece"];
                foreach (DataRow dr in dtPieces.Rows)
                {
                    Piece piece = new Piece();
                    piece.Id               = (int)dr["Id"];
                    piece.Name             = (string)dr["Name"];
                    piece.Number           = (string)dr["Number"];
                    piece.Order            = (string)dr["Order"];
                    piece.Count            = (int)dr["Count"];
                    piece.PrintedCount     = (int)dr["PrintedCount"];
                    piece.IsPrinted        = (bool)dr["IsPrinted"];
                    piece.Ots              = (string)dr["Ots"];
                    piece.DelegateNumber   = (string)dr["DelegateNumber"];
                    piece.AccessoryFactory = (string)dr["AccessoryFactory"];
                    piece.VehicleType      = (string)dr["VehicleType"];
                    piece.TestContent      = (string)dr["TestContent"];
                    piece.SendPerson       = (string)dr["SendPerson"];
                    piece.ChargePerson     = (string)dr["ChargePerson"];
                    if (DBNull.Value.Equals(dr["SendDate"]))
                    {
                        piece.SendDate = null;
                    }
                    else
                    {
                        piece.SendDate = (DateTime?)dr["SendDate"];
                    }
                    piece.Place        = (string)dr["Place"];
                    piece.IsEnable     = (bool)dr["IsEnable"];
                    piece.IsArchived   = (bool)dr["IsArchived"];
                    piece.Description  = (string)dr["Description"];
                    piece.Creater      = (int)dr["Creater"];
                    piece.CreatedDate  = (DateTime)dr["CreatedDate"];
                    piece.Modifier     = (int)dr["Modifier"];
                    piece.ModifiedDate = (DateTime)dr["ModifiedDate"];
                    listPieces.Add(piece);
                }
                //DataTable dtSignature = ds.Tables["Signature"];
                //string tempBase64String = null;
                //foreach (DataRow dr in dtSignature.Rows)
                //{
                //    tempBase64String = Convert.ToBase64String((byte[])dr["Sign"]);
                //    listSignatures.Add(new Signature
                //    {
                //        Id = (int)dr["Id"],
                //        Name = (string)dr["Name"],
                //        Sign = tempBase64String,
                //        Creater = (int)dr["Creater"],
                //        CreatedDate = (DateTime)dr["CreatedDate"]
                //    });
                //}
                //DataTable dtMessages = ds.Tables["Message"];
                //foreach (DataRow dr in dtMessages.Rows)
                //{
                //    listMessages.Add(new Message
                //    {
                //        Id = (int)dr["Id"],
                //        Type = (string)dr["Type"],
                //        IsArchived = (bool)dr["IsArchived"],
                //        Title = (string)dr["Title"],
                //        Text = (string)dr["Text"],
                //        Href = (string)dr["Href"],
                //        Creater = (int)dr["Creater"],
                //        CreatedDate = (DateTime)dr["CreatedDate"],
                //        Modifier = (int)dr["Modifier"],
                //        ModifiedDate = (DateTime)dr["ModifiedDate"]
                //    });
                //}
                DataTable dtDeleted = ds.Tables["Deleted"];
                foreach (DataRow dr in dtDeleted.Rows)
                {
                    listDeleteds.Add(new Deleted
                    {
                        Id          = (int)dr["Id"],
                        Model       = (string)dr["Model"],
                        TargetIds   = (string)dr["TargetIds"],
                        CreatedDate = (DateTime)dr["CreatedDate"]
                    });
                }
                model.Users       = listUsers;
                model.Roles       = listRoles;
                model.Projects    = listProjects;
                model.Departments = listDepartments;
                model.Oils        = listOils;
                model.Preferences = listPreferences;
                model.Cars        = listCars;
                model.Instances   = listInstances;
                model.Traces      = listTraces;
                model.Bills       = listBills;
                model.Pieces      = listPieces;
                //model.Signatures = listSignatures;
                //model.Messages = listMessages;
                model.Deleteds = listDeleteds;
                result         = true;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                result = false;
            }
            return(result);
        }
예제 #7
0
 /// <summary>
 /// 获取Changeset
 /// </summary>
 /// <returns></returns>
 public static bool GetChangeset(DateTime syncToken, ref Model.Changeset model, out string errMsg)
 {
     return(ChangesetService.GetChangeset(syncToken, ref model, out errMsg));
 }
예제 #8
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")
            });
        }