src/NetCoreBBS/Areas/Admin/Controllers/TopicRepliesController.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using NetCoreBBS.Infrastructure;
using Microsoft.AspNetCore.Authorization;
namespace NetCoreBBS.Areas.Admin.Controllers
{
[Area("Admin")]
[Authorize("Admin")]
public class TopicRepliesController : Controller
{
private readonly DataContext _context;
public TopicRepliesController(DataContext context)
{
_context = context;
}
// GET: TopicReplies
public async Task<IActionResult> Index(int id)
{
var topicreplys = _context.TopicReplys.Where(r => r.TopicId == id).ToListAsync();
return View(await topicreplys);
}
// GET: TopicReplies/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if (id == null)
{
return NotFound();
}
var topicReply = await _context.TopicReplys.SingleOrDefaultAsync(m => m.Id == id);
if (topicReply == null)
{
return NotFound();
}
var topic = await _context.Topics.SingleOrDefaultAsync(r => r.Id == topicReply.TopicId);
topic.ReplyCount -= 1;
_context.Topics.Update(topic);
_context.TopicReplys.Remove(topicReply);
await _context.SaveChangesAsync();
return NoContent();
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
