src/NetCoreBBS/Controllers/TopicController.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreBBS.Infrastructure;
using NetCoreBBS.Entities;
using NetCoreBBS.Interfaces;
using NetCoreBBS.ViewModels;
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace NetCoreBBS.Controllers
{
public class TopicController : Controller
{
private ITopicRepository _topic;
private IRepository<TopicNode> _node;
private ITopicReplyRepository _reply;
public TopicController(ITopicRepository topic, IRepository<TopicNode> node, ITopicReplyRepository reply)
{
_topic = topic;
_node = node;
_reply = reply;
}
// GET: /Topic/1
[Route("/Topic/{id}")]
public IActionResult Index(int id)
{
if (id <= 0) return Redirect("/");
var topic = _topic.GetById(id);
if (topic == null) return Redirect("/");
var replys = _reply.List(r => r.TopicId == id).ToList();
topic.ViewCount += 1;
_topic.Edit(topic);
ViewBag.Replys = replys;
return View(topic);
}
[HttpPost]
[ValidateAntiForgeryToken]
[Route("/Topic/{id}")]
public IActionResult Index([Bind("TopicId,ReplyUserId,ReplyEmail,ReplyContent")]TopicReply reply)
{
if (ModelState.IsValid&&!string.IsNullOrEmpty(reply.ReplyContent))
{
reply.CreateOn = DateTime.Now;
_reply.Add(reply);
var topic = _topic.GetById(reply.TopicId);
topic.LastReplyUserId = reply.ReplyUserId;
topic.LastReplyTime = reply.CreateOn;
topic.ReplyCount += 1;
_topic.Edit(topic);
}
return RedirectToAction("Index", "Topic", new { Id = reply.TopicId });
}
[Route("/Topic/Node/{name}")]
public IActionResult Node(string name)
{
if (string.IsNullOrEmpty(name)) return Redirect("/");
后面还有 35 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
