// PUT api/values/5 // public Hashtable Put(int id, [FromBody] string area_name, [FromBody] string name, [FromBody] string user_number) //{ public Hashtable Put(int id, string area_name, string name, string user_number) { //int admin = UserInfo.GetUserIdFromCookie(HttpContext.Current); int admin = 1; Hashtable ht = new Hashtable(); Hashtable data = new Hashtable(); AdminInfo ai = new AdminInfo(); AreaInfo ari = new AreaInfo(); /* if (ai.HasAreaUserName(name)) * { * ht.Add("code", 40000); * data.Add("message", "管理员已存在"); * } * else if(ari.HasAreaName(area_name)) * { * ht.Add("code", 40000); * data.Add("message", "部门名字已存在"); * } * else * {*/ try { if (ari.ChangeAreaName(id, area_name) && ai.ChangeAreaAdmin(id, name, null, user_number, admin)) { ht.Add("code", 20000); data.Add("status", "success"); } else { ht.Add("code", 40000); data.Add("message", "failed"); } } 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); }