Beispiel #1
0
        // POST api/values

        /*      public Hashtable Post( string area_name,string name,  string password, string user_number) {
         *
         *        Hashtable ht = new Hashtable();
         *        ht.Add("111", "111");
         *        return ht;
         *    }*/

        public Hashtable Post(string area_name, string name, string password, string user_number)
        {
            int       admin = UserInfo.GetUserIdFromCookie(HttpContext.Current);
            Hashtable ht    = new Hashtable();
            Hashtable data  = new Hashtable();
            AreaInfo  ai    = new AreaInfo();

            if (ai.HasAreaName(area_name))
            {
                ht.Add("code", 40000);
                data.Add("message", "部门已存在");
            }
            else if (new AdminInfo().HasAreaUserName(name))
            {
                ht.Add("code", 40000);
                data.Add("message", "管理员已存在");
            }
            else
            {
                try
                {
                    if (ai.AddOne(area_name, name, UserInfo.cypher(password), user_number, admin))
                    {
                        ht.Add("code", 20000);
                        data.Add("id", ai.GetId(area_name));
                    }
                    else
                    {
                        ht.Add("code", 40000);
                        data.Add("message", "error");
                    }
                }
                catch (Exception e)
                {
                    ht.Add("code", 40000);
                    data.Add("message", e.Message);
                }
            }
            ht.Add("data", data);
            return(ht);
        }
        // POST api/<controller>
        public Hashtable Post([FromBody] int id_area, [FromBody] string area_name)
        {
            Hashtable ht = new Hashtable();
            AreaInfo  ai = new AreaInfo();

            if (ai.HasAreaName(area_name))
            {
                ht.Add("state", false);
                ht.Add("reason", "部门名字已存在");
            }
            else
            {
                try
                {
                    ht.Add("state", ai.ChangeAreaName(id_area, area_name));
                }
                catch (Exception e)
                {
                    ht.Add("state", false);
                    ht.Add("reason", e.Message);
                }
            }
            return(ht);
        }