ABP入门教程10 - 展示层实现增删改查-控制器

时间:2025-04-26 14:06:13

点这里进入ABP入门教程目录

创建控制器

在展示层(即JD.CRS.Web.Mvc)的Controllers下新建一个控制器CourseController.cs

 using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Authorization;
using JD.CRS.Authorization;
using JD.CRS.Controllers;
using JD.CRS.Course;
using JD.CRS.Web.Models.Course;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks; namespace JD.CRS.Web.Controllers
{
[AbpMvcAuthorize(PermissionNames.Pages_Course)]
public class CourseController : CRSControllerBase
{
private readonly ICourseAppService _courseAppService;
const int MaxNum = ;
public CourseController(ICourseAppService courseAppService)
{
_courseAppService = courseAppService;
}
// GET: /<controller>/
public async Task<ActionResult> Index()
{
var courses = (await _courseAppService.GetAll(new PagedResultRequestDto { MaxResultCount = MaxNum })).Items;
// Paging not implemented yet
var model = new CourseListViewModel
{
Courses = courses
};
return View(model);
} public async Task<ActionResult> EditCourseModal(int courseId)
{
var course = await _courseAppService.Get(new EntityDto<int>(courseId));
var model = new EditCourseModalViewModel
{
Course = course
};
return View("_EditCourseModal", model);
}
}
}