ABP Development Notes 8 - Application Layer to create a service application

Click here to enter the ABP Development Notes directory 

Create a directory

In the application layer (ie JD.CRS.Application) New Folder Course // Course for storage-related application services

In JD.CRS.Application / Course Dto // create a new folder for storing transmission related data objects Course

Creating a Data Transfer Object

In the new JD.CRS.Application / Course / Dto two Dto

Read-only objects

CourseDto.cs // Course for querying objects

Paste AutoMapFrom features

[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 is          /// Status: Normal 0, 1 waste
 39          ///  </ Summary> 
40          public  int ? The Status { GET ; SET ;}
 41 is          ///  <Summary> 
42 is          / // creation date
 43 is          ///  </ Summary> 
44 is          public ? {a CreateDate the DateTime GET ; SET ;}
 45          ///  <Summary> 
46 is          /// created
 47          ///  </ Summary> 
48          [the 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 }
Class CourseDto

Objects can write

CreateUpdateCourseDto // create / modify objects Course

Paste AutoMapTo features

[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 is          /// Status: Normal 0, 1 waste
 39          ///  </ Summary> 
40          public  int ? The Status { GET ; SET ;}
 41 is          ///  <Summary> 
42 is          / // creation date
 43 is          ///  </ Summary> 
44 is          public ? {a CreateDate the DateTime GET ; SET ;}
 45          ///  <Summary> 
46 is          /// created
 47          ///  </ Summary> 
48          [the 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 }
CreateUpdateCourseDto

Create an application service interface

New ICourseAppService.cs in JD.CRS.Application / Course

. 1  the using Abp.Application.Services;
 2  the using Abp.Application.Services.Dto;
 . 3  the using JD.CRS.Course.Dto;
 . 4  
. 5  namespace JD.CRS.Course
 . 6  {
 . 7      public  interface ICourseAppService: IAsyncCrudAppService < // define CRUD methods 
8               CourseDto, // used to display course 
9               int , // primary key course entity 
10               PagedResultRequestDto, // get the time course for paging 
11               CreateUpdateCourseDto, // for creating courses
12 is               CreateUpdateCourseDto> // for updating the program 
13      {
 14      }
 15 }
ICourseAppService

Creating Application Services

New CourseAppService.cs in JD.CRS.Application / Course 

 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 
10     public class CourseAppService : AsyncCrudAppService<Entitys.Course, CourseDto, int, PagedResultRequestDto,
11                              CreateUpdateCourseDto, CreateUpdateCourseDto>, ICourseAppService
12 
13     {
14 
15         public CourseAppService(IRepository<Entitys.Course, int> repository)
16             : base(repository)
17         {
18 
19         }
20 
21         public override Task<CourseDto> Create(CreateUpdateCourseDto input)
22         {
23             var sin = input;
24             return base.Create(input);
25         }
26     }
27 }
CourseAppService

Guess you like

Origin www.cnblogs.com/IT-Evan/p/ABP8.html