public HttpResponseMessage Register(dynamic obj) { HttpResponseMessage response = new HttpResponseMessage(); string time; string employeeId; try { time = obj.time.Value; employeeId = obj.doctorId.Value; } catch (Exception e) { response.Content = new StringContent(e.Message); response.StatusCode = HttpStatusCode.BadRequest; return(response); } string patientId = HttpContext.Current.User.Identity.Name; if (employeeId == null || employeeId.Equals("")) { // 这url不合法 response.Content = new StringContent("Url不合法!"); response.StatusCode = HttpStatusCode.BadRequest; return(response); } else { // Url合法 EmployeeInfo employeeInfo = UserHelper.GetEmployeeInfo(employeeId); //判断医生是否有空 if (employeeInfo == null) { response.Content = new StringContent("医生不存在"); response.StatusCode = HttpStatusCode.BadRequest; } // 创建挂号记录 Treatment treatment = new Treatment(); //设置预约挂号时间段 treatment.patient_id = patientId; DateTime treatTime = Convert.ToDateTime(time); DateTime treatEndTime = treatTime.AddHours(1); treatment.start_time = treatTime; treatment.end_time = treatEndTime; //添加医生Id treatment.doc_id = employeeId; // 根据employeeId找到医生的科室 treatment.clinic = employeeInfo.clinic; // 设置挂号金额 Random ran = new Random(); treatment.pay = 100 * ran.NextDouble(); // treatment 表插入一条记录 string treatment_id = PatientHelper.RegisterTreat(treatment); if (treatment == null) { response.Content = new StringContent("挂号失败"); response.StatusCode = HttpStatusCode.BadRequest; } else { response.Content = new StringContent("挂号成功:" + "\n" + employeeId + time + "\n" + "挂号单id:" + treatment_id); response.StatusCode = HttpStatusCode.OK; } // 得到这条记录的主码 // takes表插入患者id treatment id 医生id设为空, 等接诊成功时再填充doc_id } //response.Content = new StringContent(employeeId + " " + time); return(response); }