abp(net core)+easyui+efcore实现仓储管理系统目录
abp(net core)+easyui+efcore实现仓储管理系统——创建应用服务(五)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之控制器(六)
abp(net core)+easyui+efcore实现仓储管理系统——EasyUI前端页面框架 (十八)
在上一篇 abp(net core)+easyui+efcore实现仓储管理系统——ABP WebAPI与EasyUI结合增删改查之一(二十七) 文章中我们学习了TreeGrid的一些基础知识,接下我们来创建我们开发组织管理功能用到的一些类。关于如何创建类我们之前的文章中已经写了很多了,这里会有些简略。
四、定义应用服务接口需要用到的DTO类
为了在进行查询时使用, PagedOrgResultRequestDto被用来将模块数据传递到基础设施层.
1. 在Visual Studio 2017的“解决方案资源管理器”中,右键单击“ABP.TPLMS.Application”项目,在弹出菜单中选择“添加” > “新建文件夹”,并重命名为“Orgs”
2. 使用鼠标右键单击我们刚才创建的“Orgs”文件夹,在弹出菜单中选择“添加” > “新建文件夹”,并重命名为“Dto”。
3.右键单击“Dto”文件夹,然后选择“添加” > “类”。 将类命名为 Paged OrgResultRequestDto,然后选择“添加”。代码如下。
using Abp.Application.Services.Dto;
using Abp.Application.Services.Dto;
using System;
using System.Collections.Generic;
using System.Text;
namespace ABP.TPLMS.Orgs.Dto
{
public class PagedOrgResultRequestDto : PagedResultRequestDto
{
public string Keyword { get; set; }
}
}
4.右键单击“Dto”文件夹,然后选择“添加” > “类”。 将类命名为 OrgDto,然后选择“添加”。代码如下。
using Abp.Application.Services.Dto;
using Abp.AutoMapper;
using ABP.TPLMS.Entitys;
using System;
using System.Collections.Generic;
using System.Text;
namespace ABP.TPLMS.Orgs.Dto
{
[AutoMapFrom(typeof(Org))]
public class OrgDto : EntityDto<int>
{
int m_parentId = 0;
public string Name { get; set; }
public string HotKey { get; set; }
public int ParentId { get { return m_parentId; } set { m_parentId = value; } }
public string ParentName { get; set; }
public bool IsLeaf { get; set; }
public bool IsAutoExpand { get; set; }
public string IconName { get; set; }
public int Status { get; set; }
public int Type { get; set; }
public string BizCode { get; set; }
public string CustomCode { get; set; }
public DateTime CreationTime { get; set; }
public DateTime UpdateTime { get; set; }
public int CreateId { get; set; }
public int SortNo { get; set; }
public int _parentId {
get { return m_parentId; }
}
}
}
using Abp.Application.Services.Dto;
using Abp.AutoMapper;
using ABP.TPLMS.Entitys;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace ABP.TPLMS.Orgs.Dto
{
[AutoMapTo(typeof(Org))]
public class CreateUpdateOrgDto : EntityDto<int>
{
public string Name { get; set; }
[StringLength(255)]
public string HotKey { get; set; }
public int ParentId { get; set; }
[Required]
[StringLength(255)]
public string ParentName { get; set; }
public bool IsLeaf { get; set; }
public bool IsAutoExpand { get; set; }
[StringLength(255)]
public string IconName { get; set; }
public int Status { get; set; }
public int Type { get; set; }
[StringLength(255)]
public string BizCode { get; set; }
[StringLength(100)]
public string CustomCode { get; set; }
public DateTime CreationTime { get; set; }
public DateTime UpdateTime { get; set; }
public int CreateId { get; set; }
public int SortNo { get; set; }
}
}
五、定义IOrgAppService接口
6. 在Visual Studio 2017的“解决方案资源管理器”中,鼠标右键单击“Org”文件夹,然后选择“添加” > “新建项”,在弹出对话框中选择“接口”。为应用服务定义一个名为 IOrgAppService 的接口。代码如下。
using System;
using System.Collections.Generic;
using System.Text;
using Abp.Application.Services;
using ABP.TPLMS.Orgs.Dto;
namespace ABP.TPLMS.Orgs
{
public interface IOrgAppService : IAsyncCrudAppService<//定义了CRUD方法
OrgDto, //用来展示组织信息
int, //Org实体的主键
PagedOrgResultRequestDto, //获取组织信息的时候用于分页
CreateUpdateOrgDto, //用于创建组织信息
CreateUpdateOrgDto> //用于更新组织信息
{
}
}
六、实现IOrgAppService
7.在Visual Studio 2017的“解决方案资源管理器”中,右键单击“Org”文件夹,然后选择“添加” > “新建项”,在弹出对话框中选择“类”。为应用服务定义一个名为 OrgAppService 的服务类。代码如下。
using Abp.Application.Services;
using Abp.Domain.Repositories;
using ABP.TPLMS.Entitys;
using ABP.TPLMS.Orgs.Dto;
using System;
using System.Collections.Generic;
using System.Text;
namespace ABP.TPLMS.Orgs
{
public class OrgAppService : AsyncCrudAppService<Org, OrgDto, int, PagedOrgResultRequestDto,
CreateUpdateOrgDto, CreateUpdateOrgDto>, IOrgAppService
{
public OrgAppService(IRepository<Org, int> repository)
: base(repository)
{
}
}
}
1. 在Visual Studio 2017的“解决方案资源管理器”中,右键单击在领域层“ABP.TPLMS.Web.Mvc”项目中的Controller目录。 选择“添加” > “新建项…”。如下图。

2. 在弹出对话框“添加新项-ABP.TPLMS.Web.Mvc”中选择“控制器类”,然后在名称输入框中输入“OrgsController”,然后点击“添加”按钮。
3.在OrgsController.cs文件中输入如下代码,通过构造函数注入对应用服务的依赖。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.AspNetCore.Mvc.Authorization;
using Abp.Web.Models;
using ABP.TPLMS.Controllers;
using ABP.TPLMS.Orgs;
using ABP.TPLMS.Orgs.Dto;
using ABP.TPLMS.Web.Models.Orgs;
using Microsoft.AspNetCore.Mvc;
namespace ABP.TPLMS.Web.Controllers
{
[AbpMvcAuthorize]
public class OrgsController : TPLMSControllerBase
{
private readonly IOrgAppService _orgAppService;
private const int MAX_COUNT= 1000;
public OrgsController(IOrgAppService orgAppService)
{
_orgAppService = orgAppService;
}
[HttpGet]
// GET: /<controller>/
public IActionResult Index()
{
return View();
}
[DontWrapResult]
[HttpPost]
public string List()
{
PagedOrgResultRequestDto paged = new PagedOrgResultRequestDto();
paged.MaxResultCount = MAX_COUNT;
var userList = _orgAppService.GetAll(paged).GetAwaiter().GetResult().Items;
int total = userList.Count;
var json = JsonEasyUI(userList, total);
return json;
}
}
}