Example #1
0
        public void listByName(HttpContext context)
        {
            context.Response.ContentType     = "text/plain";
            context.Request.ContentEncoding  = Encoding.UTF8;
            context.Response.ContentEncoding = Encoding.UTF8;
            List <Requirement>          list       = requirementService.getRequirementListByName(context.Request["searchname"].ToString());
            StringBuilder               jsonString = new StringBuilder();
            Dictionary <String, Object> dictionary = new Dictionary <string, object>();
            //jsonString.Append("\"supply\":");
            string imgPath = "hotel1.jpg";

            if (list.Count == 0)
            {
                context.Response.Write("{\"success\":\"false\"}");
                return;
            }
            jsonString.Append("[");
            int i = 1;

            foreach (Requirement requirement in list)
            {
                RequirementImg requirementImg = requirementService.getRequirementFirstImg(requirement.Id);
                if (requirementImg.ImgPath != null)
                {
                    imgPath = System.IO.Path.GetFileName(requirementImg.ImgPath);
                }

                dictionary.Add("Id", requirement.Id);
                dictionary.Add("Name", requirement.RequirementName);
                dictionary.Add("Desc", requirement.RequirementDesc);
                dictionary.Add("categoryId", requirement.RequirementCategory.Id);
                dictionary.Add("priority", requirement.Priority);
                dictionary.Add("userId", requirement.User.Id);
                dictionary.Add("nickName", requirement.User.NickName);
                dictionary.Add("teleNumber", requirement.User.TeleNumber);
                dictionary.Add("createTime", requirement.CreateTime);
                dictionary.Add("modifyTime", requirement.ModifyTime);
                dictionary.Add("Status", requirement.RequirementStatus);
                dictionary.Add("FirstImgPath", imgPath);
                dictionary.Add("success", "true");
                jsonString.Append(JsonUtil.toJson(dictionary));
                if (i < list.Count)
                {
                    jsonString.Append(",");
                }
                i++;
                dictionary.Clear();
            }
            jsonString.Append("]");
            context.Response.Write(jsonString.ToString());
        }