public void AddRoom(HttpListenerContext context) { var request = context.Request; var response = context.Response; string title = request.QueryString["title"]; string description = request.QueryString["description"]; string time = request.QueryString["time"]; string attendance = request.QueryString["attendance"]; // 验证token string token = request.QueryString["token"]; if (!UserHandler.ValidateToken(token)) { ResponseTokenInvalid(context); return; } if (title == null || description == null || time == null || attendance == null) { ResponseParameterInvalid(context); return; } title = Encoding.GetEncoding("utf-8").GetString(request.ContentEncoding.GetBytes(title)); description = Encoding.GetEncoding("utf-8").GetString(request.ContentEncoding.GetBytes(description)); string uid = UserHandler.GetUidByToken(token); Dictionary <string, object> result = new Dictionary <string, object>(); Room room = RoomService.AddRoom(int.Parse(uid), title, description, int.Parse(time), int.Parse(attendance)); if (room != null) { result.Add("code", 0); result.Add("data", room.ToJson()); } else { result.Add("code", -1); result.Add("msg", "operate fail"); } Response(context, result); }
public void DeleteRoom(HttpListenerContext context) { var request = context.Request; var response = context.Response; string id = request.QueryString["id"]; // 验证token string token = request.QueryString["token"]; if (!UserHandler.ValidateToken(token)) { ResponseTokenInvalid(context); return; } if (id == null) { ResponseParameterInvalid(context); return; } Dictionary <string, object> result = new Dictionary <string, object>(); bool success = RoomService.SoftDeleteRoom(int.Parse(id)); if (success) { result.Add("code", 0); Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("id", int.Parse(id)); result.Add("data", data); } else { result.Add("code", -1); result.Add("msg", "operate fail"); } Response(context, result); }
public void AddUser(HttpListenerContext context) { var request = context.Request; var response = context.Response; string id = request.QueryString["id"]; // 验证token string token = request.QueryString["token"]; if (!UserHandler.ValidateToken(token)) { ResponseTokenInvalid(context); return; } if (id == null) { ResponseParameterInvalid(context); return; } Dictionary <string, object> result = new Dictionary <string, object>(); Record record = RecordService.GetRecordByID(int.Parse(id)); if (record != null) { result.Add("code", 0); result.Add("data", record.ToJson()); } else { result.Add("code", -1); result.Add("msg", "operate fail"); } Response(context, result); }