Exemplo n.º 1
0
        //评价医生
        public HttpResponseMessage Comment(dynamic obj)
        {
            string patient_id = HttpContext.Current.User.Identity.Name;

            HttpResponseMessage response = new HttpResponseMessage();

            // 向evaluation插入相关评价
            // 返回评价后的界面

            //反序列化的过程

            Evaluation evaluation = new Evaluation();

            try
            {
                evaluation = JsonConvert.DeserializeAnonymousType(JsonObjectConverter.ObjectToJson(obj), evaluation);
            }
            catch (Exception e)
            {
                response.Content    = new StringContent("参数传递出错,反序列化失败!");
                response.StatusCode = HttpStatusCode.Forbidden;
                return(response);
            }
            evaluation.patient_id = patient_id;

            //数据库更新相关评论
            //多次评价限制
            try
            {
                if (!PatientHelper.Comment(evaluation))
                {
                    response.Content    = new StringContent("由于某些原因,评价失败~");
                    response.StatusCode = HttpStatusCode.Forbidden;
                }
                else
                {
                    response.Content    = new StringContent("评价成功~");
                    response.StatusCode = HttpStatusCode.OK;
                }
            }
            catch (Exception e)
            {
                response.Content    = new StringContent("只能评价一次哦~");
                response.StatusCode = HttpStatusCode.BadRequest;
            }

            return(response);
        }