ABP入門教程8 - 應用層創建應用服務


點這里進入ABP入門教程目錄 

創建目錄

在應用層(即JD.CRS.Application)下創建文件夾Course //用以存放Course相關應用服務

在JD.CRS.Application/Course下創建文件夾Dto //用以存放Course相關數據傳輸對象

創建數據傳輸對象

在JD.CRS.Application/Course/Dto下創建兩個Dto

只讀對象

CourseDto.cs //用於查詢Course對象

貼上AutoMapFrom的特性

[AutoMapFrom(typeof(Entitys.Course))]

 1 using Abp.Application.Services.Dto;
 2 using Abp.AutoMapper;
 3 using System;
 4 using System.ComponentModel.DataAnnotations;
 5 
 6 namespace JD.CRS.Course.Dto
 7 {
 8 
 9     [AutoMapFrom(typeof(Entitys.Course))]
10     public class CourseDto : EntityDto<int>
11     {
12         /// <summary>
13         /// 課程編號
14         /// </summary>
15         [StringLength(50)]
16         public string Code { get; set; }
17         /// <summary>
18         /// 院系編號
19         /// </summary>
20         [StringLength(50)]
21         public string DepartmentCode { get; set; }
22         /// <summary>
23         /// 課程名稱
24         /// </summary>
25         [StringLength(150)]
26         public string Name { get; set; }
27         /// <summary>
28         /// 課程積分
29         /// </summary>
30         [Range(0, 5)]
31         public int Credits { get; set; }
32         /// <summary>
33         /// 備注
34         /// </summary>
35         [StringLength(200)]
36         public string Remarks { get; set; }
37         /// <summary>
38         /// 狀態: 0 正常, 1 廢棄
39         /// </summary>
40         public int? Status { get; set; }
41         /// <summary>
42         /// 創建日期
43         /// </summary>
44         public DateTime? CreateDate { get; set; }
45         /// <summary>
46         /// 創建人
47         /// </summary>
48         [StringLength(50)]
49         public string CreateName { get; set; }
50         /// <summary>
51         /// 修改日期
52         /// </summary>
53         public DateTime? UpdateDate { get; set; }
54         /// <summary>
55         /// 修改人
56         /// </summary>
57         [StringLength(50)]
58         public string UpdateName { get; set; }
59 
60         public DateTime CreationTime { get; set; }
61     }
62 }
View Code

可寫對象

CreateUpdateCourseDto.cs //用於創建/修改Course對象

貼上AutoMapTo的特性

[AutoMapTo(typeof(Entitys.Course))]

 1 using Abp.Application.Services.Dto;
 2 using Abp.AutoMapper;
 3 using System;
 4 using System.ComponentModel.DataAnnotations;
 5 
 6 namespace JD.CRS.Course.Dto
 7 {
 8 
 9     [AutoMapTo(typeof(Entitys.Course))]
10     public class CreateUpdateCourseDto : EntityDto<int>
11     {
12         /// <summary>
13         /// 課程編號
14         /// </summary>
15         [StringLength(50)]
16         public string Code { get; set; }
17         /// <summary>
18         /// 院系編號
19         /// </summary>
20         [StringLength(50)]
21         public string DepartmentCode { get; set; }
22         /// <summary>
23         /// 課程名稱
24         /// </summary>
25         [StringLength(150)]
26         public string Name { get; set; }
27         /// <summary>
28         /// 課程積分
29         /// </summary>
30         [Range(0, 5)]
31         public int Credits { get; set; }
32         /// <summary>
33         /// 備注
34         /// </summary>
35         [StringLength(200)]
36         public string Remarks { get; set; }
37         /// <summary>
38         /// 狀態: 0 正常, 1 廢棄
39         /// </summary>
40         public int? Status { get; set; }
41         /// <summary>
42         /// 創建日期
43         /// </summary>
44         public DateTime? CreateDate { get; set; }
45         /// <summary>
46         /// 創建人
47         /// </summary>
48         [StringLength(50)]
49         public string CreateName { get; set; }
50         /// <summary>
51         /// 修改日期
52         /// </summary>
53         public DateTime? UpdateDate { get; set; }
54         /// <summary>
55         /// 修改人
56         /// </summary>
57         [StringLength(50)]
58         public string UpdateName { get; set; }
59 
60         public DateTime CreationTime { get; set; }
61     }
62 }
View Code

創建應用服務接口

在JD.CRS.Application/Course下新建項/接口

ICourseAppService.cs

 1 using Abp.Application.Services;
 2 using Abp.Application.Services.Dto;
 3 using JD.CRS.Course.Dto;
 4 
 5 namespace JD.CRS.Course
 6 {
 7     public interface ICourseAppService : IAsyncCrudAppService<//定義了CRUD方法
 8              CourseDto, //用來展示課程
 9              int, //Course實體的主鍵
10              PagedResultRequestDto, //獲取課程的時候用於分頁
11              CreateUpdateCourseDto, //用於創建課程
12              CreateUpdateCourseDto> //用於更新課程
13     {
14     }
15 }
View Code

創建應用服務

在JD.CRS.Application/Course下新建項/類

CourseAppService.cs

 1 using Abp.Application.Services;
 2 using Abp.Application.Services.Dto;
 3 using Abp.Domain.Repositories;
 4 using JD.CRS.Course.Dto;
 5 using System.Threading.Tasks;
 6 
 7 namespace JD.CRS.Course
 8 {
 9     public class CourseAppService : AsyncCrudAppService<Entitys.Course, CourseDto, int, PagedResultRequestDto,
10                              CreateUpdateCourseDto, CreateUpdateCourseDto>, ICourseAppService
11 
12     {
13         public CourseAppService(IRepository<Entitys.Course, int> repository)
14             : base(repository)
15         {
16 
17         }
18 
19         public override Task<CourseDto> Create(CreateUpdateCourseDto input)
20         {
21             var sin = input;
22             return base.Create(input);
23         }
24     }
25 }
View Code


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM