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
posted @ 2019-10-03 00:01  智慧园区-老朱  阅读(2632)  评论(4编辑  收藏  举报