public HttpResponseMessage AddEmployee(dynamic obj) { HttpResponseMessage response = new HttpResponseMessage(); Employee emp = new Employee(); Identity identity = new Identity(); try { var employee = JsonConvert.DeserializeObject(JsonObjectConverter.ObjectToJson(obj)) as JObject; emp.clinic = employee.GetValue("clinic_name").ToString(); emp.credit_num = employee.GetValue("credit_num").ToString(); emp.password = employee.GetValue("password").ToString(); emp.post = employee.GetValue("post").ToString(); emp.salary = double.Parse(employee.GetValue("salary").ToString()); emp.department = employee.GetValue("dept_name").ToString(); identity.credit_num = emp.credit_num; identity.name = employee.GetValue("name").ToString(); identity.sex = char.Parse(employee.GetValue("sex").ToString()); identity.birth = Convert.ToDateTime(employee.GetValue("birth").ToString()); } catch (Exception e) { response.Content = new StringContent("数据格式错误:" + e.Message); return(response); } try { ManagementHelper.AddEmployee(identity, emp); } catch (Exception e) { response.Content = new StringContent(e.Message); response.StatusCode = HttpStatusCode.BadRequest; return(response); } response.Content = new StringContent("添加成功!" + JsonObjectConverter.ObjectToJson(emp)); // 数据库中插入 return(response); }