public ActionResult deleteTopicAnswerByID(string answerID) { int deleteTopicAnswerFlag = 0; Dictionary <string, string> returnJson = new Dictionary <string, string>(); try { TopicAnswerReply topicAnswerReply = entity.TopicAnswerReply.Single(c => c.TopicAnswerId == int.Parse(answerID)); //查找 entity.TopicAnswerReply.Remove(topicAnswerReply); //建立删除语句 entity.SaveChanges(); //提交删除 deleteTopicAnswerFlag = 1; //成功 returnJson.Add("deleteTopicAnswerID", topicAnswerReply.TopicAnswerId.ToString()); } catch (Exception e) { deleteTopicAnswerFlag = 0; //失败 } finally { returnJson.Add("deleteTopicAnswerFlag", deleteTopicAnswerFlag.ToString()); } return(Json(returnJson)); }
public ActionResult createTopicAnswerByID() { DateTime dateTime = DateTime.Now; //获取当前时间 int cerateTopicAnswerFlag = 0; try { //获取参数 string content = Request.Form["content"]; string topicID = Request.Form["topicID"]; string userID = Request.Form["userID"]; string parentID = Request.Form["parentID"]; //新建answer TopicAnswerReply topicAnswerReply = new TopicAnswerReply { TopicId = int.Parse(topicID), AnswerLikes = 0, AnswerContent = content, UserId = int.Parse(userID), AnswerUploadTime = dateTime, ParentAnswerId = int.Parse(parentID), }; entity.TopicAnswerReply.Add(topicAnswerReply); int nums = entity.SaveChanges(); //更新相应topic answer数量 Topic topic = entity.Topic.Single(c => c.TopicId == int.Parse(topicID)); topic.AnswerNum += 1; entity.Topic.Update(topic); entity.SaveChanges(); cerateTopicAnswerFlag = 1; } catch (Exception e) { cerateTopicAnswerFlag = 0; Console.WriteLine(e.Message); } return(Json(new { cerateTopicAnswerFlag = cerateTopicAnswerFlag })); }