//保存题库 public int SaveSource(TopicSource topicScouce) { int res = 0; try { //更新 if (topicScouce.TopicSourceId != 0) { TopicSource newSource = db.TopicSource.First(t => t.TopicSourceId == topicScouce.TopicSourceId); newSource.TopicSourceName = topicScouce.TopicSourceName; db.SubmitChanges(); } else //添加 { TopicSource newSource = new TopicSource(); newSource.TopicSourceName = topicScouce.TopicSourceName; newSource.IsChose = 0; //默认未被选中 db.TopicSource.InsertOnSubmit(newSource); db.SubmitChanges(); } res = 1; } catch (Exception ex) { res = 0; } return(res); }
public async Task <ActionResult> GetServerInfo([FromQuery] string address = "whipit.de", [FromQuery] ushort port = 1337) { // TODO: Think about how I wanna cache responses if (!await Utils.IsValidAddress(address)) { return(BadRequest()); } try { TopicSource topic = new TopicSource(address, port); var queryResponse = topic.Query("status"); return(Ok(new SS13Status(queryResponse.AsText))); } catch (System.Net.Sockets.SocketException e) { // Return badrequest to tell the consumer they f****d up return(BadRequest(new { Title = "One or more validation errors occured", Status = 400, ErrorMessage = e.Message, Errors = new Dictionary <string, string[]> { { "address", new[] { $"The value '{address}' is not valid" } } } })); } }
protected void Button_Insert_Click(object sender, EventArgs e) { if (IsValid) { TopicSource.InsertParameters["Top_Name"].DefaultValue = TextBox_Top_Name.Text; TopicSource.InsertParameters["Crs_Id"].DefaultValue = DropDownList_Crs.SelectedValue; TopicSource.Insert(); } }
//删除题库名称 public int DeleteSource(int id) { int res = 0; try { TopicSource source = db.TopicSource.First(t => t.TopicSourceId == id); db.TopicSource.DeleteOnSubmit(source); db.SubmitChanges(); res = 1; } catch (Exception ex) { res = 0; } return(res); }
public ActionResult Test([FromQuery] string address = "whipit.de", [FromQuery] ushort port = 1337, [FromQuery] string query = "status") { try { TopicSource topic = new TopicSource(address, port); var queryResponse = topic.Query(query); return(Ok(queryResponse.ToString())); } catch (System.Net.Sockets.SocketException e) { return(BadRequest(new { Title = "One or more validation errors occured", Status = 400, ErrorMessage = e.Message, Errors = new Dictionary <string, string[]> { { "address", new[] { $"The value '{address}' is not valid" } } } })); } }