public void GetUser(HttpContext context) { context.Response.Write(OutputJson.Response("ok", "成功", new List <object>() { new { Name = "小明" }, new { Name = "运数注定难通全" }, new { Name = "人谋怎似所天休" } })); }
public void GetBooks(HttpContext context) { string type = context.Request["type"]; if (string.IsNullOrEmpty(type) || type == "0" || type == "undefined") { int index = 1; foreach (Book book in list) { book.Index = index.ToString(); index++; } context.Response.Write(OutputJson.Response("1", "成功", list)); } else if (type == "1") { context.Response.Write(OutputJson.Response("1", "成功", list.Where(o => o.Type == "1").ToList())); } else if (type == "2") { context.Response.Write(OutputJson.Response("1", "成功", list.Where(o => o.Type == "2").ToList())); } else if (type == "3") { context.Response.Write(OutputJson.Response("1", "成功", list.Where(o => o.Type == "3").ToList())); } }
public void Addbook(HttpContext context) { string name = context.Request["name"]; string author = context.Request["author"]; string explain = context.Request["explain"]; string type = context.Request["type"]; DateTime time = DateTime.Now; Book book = new Book() { Name = name, Author = author, Explain = explain, Time = time, Type = type, BookId = (list.Count + 1).ToString(), Index = (list.Where(o => o.Type == type).ToList().Count + 1).ToString() }; list.Add(book); context.Response.Write(OutputJson.Response("1", "成功", "")); }