public ActionResult createTopicAnswerByID(string content, string topicID, string userID) { DateTime time = new DateTime(); Topic topic = new Topic { TopicId = int.Parse(topicID), TopicContent = content, AnswerNum = 0, UserId = int.Parse(userID), TopicUploadTime = time, }; entity.Add(topic); int nums = entity.SaveChanges(); return(Json(new { a = 1 })); }
public async Task <IActionResult> Create([Bind("MensagemId,Titulo,Descricao,Categoria")] Mensagem mensagem) { if (ModelState.IsValid) { _context.Add(mensagem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mensagem)); }
public async Task <IActionResult> Create([Bind("ComentarioId,Titulo,Descricao,DataComentario,Autor")] Comentario comentario) { if (ModelState.IsValid) { _context.Add(comentario); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(comentario)); }
public async Task <IActionResult> Create([Bind("CategoriaId,Descricao")] Categoria categoria) { if (ModelState.IsValid) { _context.Add(categoria); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categoria)); }
public ActionResult createTopicByID() { DateTime dateTime = DateTime.Now; //获取当前时间 Topic topic = new Topic(); //新建topic条目项 int createTopicFlag = 0; try { //获取参数 string content = Request.Form["content"]; string title = Request.Form["title"]; string userID = Request.Form["userID"]; string zoneID = Request.Form["zoneID"]; //向条目中插入数据 topic.TopicContent = content; topic.TopicTitle = title; topic.AnswerNum = 0; topic.UserId = int.Parse(userID); topic.TopicUploadTime = dateTime; topic.ZoneId = int.Parse(zoneID); var zoneContent = (from c in entity.Zone where c.ZoneId == int.Parse(zoneID) select c).FirstOrDefault(); zoneContent.ZoneTopicNum += 1; entity.Zone.Update(zoneContent); entity.SaveChanges(); entity.Add(topic); createTopicFlag = entity.SaveChanges(); //存入数据库 返回值为1表示成功 entity.Entry(topic); createTopicFlag = 1; return(Json(new { topicDetail = topic, createTopicFlag = createTopicFlag })); } catch (Exception e) { Console.WriteLine(e.Message); createTopicFlag = 0; return(Json(new { createTopicFlag = createTopicFlag })); } }