/// <summary> /// TopicId = -1 for add /// </summary> /// <param name="topic"></param> /// <returns></returns> public static int Add_Update_Topic(TopicVO topic) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); SqlCommand cmd = new SqlCommand("add_update_topic", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@topicId", topic.TopicId); cmd.Parameters.AddWithValue("@subject", topic.Subject); cmd.Parameters.AddWithValue("@content", topic.Content); cmd.Parameters.AddWithValue("@stateCode", topic.StateCode); cmd.Parameters.AddWithValue("@categoryId", topic.CategoryId); int topicId = 0; try { conn.Open(); string result = cmd.ExecuteScalar().ToString(); if (!string.IsNullOrEmpty(result)) { topicId = Convert.ToInt32(result); } return(topicId); } catch (Exception ex) { string debug = ex.Message; throw; } finally { conn.Close(); } }
public IActionResult PostNewTopic(long groupId, [FromBody] dynamic json) { long topicId = json.id; try { TopicVO topicSelectedByGroup = _iTopicService.GetTopicByTopicId(topicId); _iSeminarGroupService.InsertTopicByGroupId(groupId, topicId); string uri = "/group/" + groupId + "/topic/" + topicId; return(Created(uri, topicSelectedByGroup)); } catch (TopicNotFoundException) { return(NotFound()); } catch (GroupNotFoundException) { return(NotFound()); } }
public string AddUpdateTopic(string topicId, string subject, string content, string state, string category) { int updatedTopicId = (string.IsNullOrEmpty(topicId)) ? -1 : Convert.ToInt32(topicId); try { TopicVO topic = new TopicVO() { TopicId = updatedTopicId, Subject = subject, Content = content, StateCode = state, CategoryId = category }; updatedTopicId = SrvTools.Add_Update_Topic(topic); } catch (Exception ex) { Context.Response.Write(ex.Message); } return(updatedTopicId.ToString()); }
/// <summary> /// Single Topic Detail: Get Topic by TopicId /// </summary> /// <param name="topicId"></param> /// <returns></returns> public static TopicVO GetTopics_by_TopicId(int topicId) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); SqlCommand cmd = new SqlCommand("get_topic_by_topicId", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@topicId", topicId); try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); TopicVO topic = null; if (reader.HasRows) { topic = new TopicVO { TopicId = Convert.ToInt16(reader["topicId"]), Subject = reader["subject"].ToString(), Content = reader["content"].ToString() }; } return(topic); } catch (Exception ex) { string debug = ex.Message; throw; } finally { conn.Close(); } }
public IActionResult GetTopic(long topicId) { try { // Fetch topic from database... Topic topic = _iTopicService.GetTopicByTopicId(topicId); // 未解决:如何求GroupLeft TopicVO topicVO = topic; // Success return(Json(topicVO)); } //If topic not found, 返回404 catch (TopicNotFoundException) { return(NotFound(new { msg = "未找到该话题!" })); } //topicId 格式错误,返回400 catch (ArgumentException) { return(BadRequest(new { msg = "错误的ID格式!" })); } }