欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十二)

程序员文章站 2023-11-11 08:31:16
上接(abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十一)),在这一篇文章中我们创建服务接口与服务实现类,并创建控制器类。 ......

abp(net core)+easyui+efcore实现仓储管理系统目录

abp(net core)+easyui+efcore实现仓储管理系统——abp总体介绍(一)

abp(net core)+easyui+efcore实现仓储管理系统——解决方案介绍(二)

abp(net core)+easyui+efcore实现仓储管理系统——领域层创建实体(三)

 abp(net core)+easyui+efcore实现仓储管理系统——定义仓储并实现 (四)

abp(net core)+easyui+efcore实现仓储管理系统——创建应用服务(五)

abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之控制器(六)

abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之列表视图(七)

abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之增删改视图(八)

abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之菜单与测试(九)

abp(net core)+easyui+efcore实现仓储管理系统——使用 webapi实现curd (十一)

 

上接(abp(net core)+easyui+efcore实现仓储管理系统——使用 webapi实现curd (十一)),在这一篇文章中我们创建服务接口与服务实现类,并创建控制器类。

 

 

二、定义应用服务接口需要用到的分页类

 

     为了在进行查询时使用, pagedsupplierresultrequestdto被用来将模块数据传递到基础设施层.

 

      1. 在visual studio 2017的“解决方案资源管理器”中,右键单击“abp.tplms.application”项目,在弹出菜单中选择“添加” > “新建文件夹”,并重命名为“suppliers”

 

      2. 使用鼠标右键单击我们刚才创建的“suppliers”文件夹,在弹出菜单中选择“添加” > “新建文件夹”,并重命名为“dto”。

 

      3.右键单击“dto”文件夹,然后选择“添加” > “类”。 将类命名为 pagedsupplierresultrequestdto,然后选择“添加”。代码如下。

 

using abp.application.services.dto;
using system;
using system.collections.generic;
using system.text;
 

namespace abp.tplms.supplier.dto
{
     public class pagedsupplierresultrequestdto : pagedresultrequestdto
    {
        public string keyword { get; set; }
     }
}

 

 

     4.右键单击“dto”文件夹,然后选择“添加” > “类”。 将类命名为 supplierdto,然后选择“添加”。代码如下。

 

using abp.application.services.dto;
using abp.automapper;
using abp.tplms.entitys;
using system;
using system.collections.generic;
using system.text; 

namespace abp.tplms.suppliers.dto
{

    [automapfrom(typeof(supplier))]
    public class supplierdto : entitydto<int>
    {

        public string address { get; set; }

        public string name { get; set; }  
        public string email { get; set; }

        public string code { get; set; }
        public int sex { get; set; }      

        public string linkname { get; set; }

        public int status { get; set; }
        public string tel { get; set; }  
        public string mobile { get; set; }

        public datetime creationtime { get; set; }
    }
}

 

 

      5.右键单击“dto”文件夹,然后选择“添加” > “类”。 将类命名为 createupdatesupplierdto,然后选择“添加”。代码如下。

 

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.suppliers.dto
{

    [automapto(typeof(supplier))]
    public  class createupdatesupplierdto : entitydto<int>
    {

        public const int maxlength = 255;
        [stringlength(maxlength)]
        public string address { get; set; }

        [required]
        [stringlength(maxlength)]
        public string name { get; set; }

        [required]
        [stringlength(maxlength)]
        public string email { get; set; }

        [required]
        [stringlength(50)]
        public string code { get; set; }
        public int sex { get; set; } 

        [stringlength(maxlength)]
        public string linkname { get; set; }
        public int status { get; set; }

        [required]
        [stringlength(maxlength)]
        public string tel { get; set; }

        [stringlength(maxlength)]
        public string mobile { get; set; }
    }
}

 

 

三、定义isupplierappservice接口

 

      6. 在visual studio 2017的“解决方案资源管理器”中,鼠标右键单击“suppliers”文件夹,然后选择“添加” > “新建项”,在弹出对话框中选择“接口”。为应用服务定义一个名为 isupplierappservice 的接口。代码如下。

 

 

using abp.application.services;
using abp.tplms.suppliers.dto;
using system;
using system.collections.generic;
using system.text; 

namespace abp.tplms.suppliers
{
    public interface isupplierappservice : iasynccrudappservice<//定义了crud方法
             supplierdto, //用来展示供应商
             int, //supplier实体的主键
             pagedsupplierresultrequestdto, //获取供应商的时候用于分页
             createupdatesupplierdto, //用于创建供应商
             createupdatesupplierdto> //用于更新供应商
    {
    }
}

 

 

四、实现isupplierappservice

 

        7.在visual studio 2017的“解决方案资源管理器”中,右键单击“suppliers”文件夹,然后选择“添加” > “新建项”,在弹出对话框中选择“类”。为应用服务定义一个名为 supplierappservice 的服务类。代码如下。

 

using abp.application.services;
using abp.domain.repositories;
using abp.tplms.entitys;
using abp.tplms.suppliers.dto;
using system;
using system.collections.generic;
using system.text;
 

namespace abp.tplms.suppliers
{

   public class supplierappservice :asynccrudappservice<supplier, supplierdto, int, pagedsupplierresultrequestdto,
                            createupdatesupplierdto, createupdatesupplierdto>,isupplierappservice      

    {

        public supplierappservice(irepository<supplier, int> repository)
            : base(repository)
    {            

    }

        public override task<supplierdto> create(createupdatesupplierdto input)
        {
            var sin = input;
            return base.create(input);
        }
    }
}

 

 

     五 创建suppliercontroller继承自tplmscontrollerbase

 

     1. 在visual studio 2017的“解决方案资源管理器”中,右键单击在领域层“abp.tplms.web.mvc”项目中的controller目录。 选择“添加” > “新建项…”。如下图。

 

 abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十二)

 

      2. 在弹出对话框“添加新项-abp.tplms.web.mvc”中选择“控制器类”,然后在名称输入框中输入“suppliercontroller”,然后点击“添加”按钮。如下图。

 

 abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十二)

 

     3.在suppliercontroller.cs文件中输入如下代码,通过构造函数注入对应用服务的依赖。

 

using system;
using system.collections.generic;
using system.linq;
using system.threading.tasks;
using abp.application.services.dto;
using abp.aspnetcore.mvc.authorization;
using abp.runtime.validation;
using abp.tplms.controllers;
using abp.tplms.suppliers;
using abp.tplms.suppliers.dto;
using abp.tplms.web.models.supplier;
using microsoft.aspnetcore.mvc;
using microsoft.entityframeworkcore;
 

namespace abp.tplms.web.controllers
{

    [abpmvcauthorize]
    public class suppliercontroller : tplmscontrollerbase
    {
        const int maxnum= 10;
        // get: /<controller>/
        public async task<iactionresult> index()
        {     

            var module = (await _supplierappservice.getall(new pagedsupplierresultrequestdto { maxresultcount = maxnum })).items;
// paging not implemented yet supplierdto cumodule = module.first(); var model = new supplierlistviewmodel { supplier = cumodule, suppliers=module }; return view(model); } private readonly isupplierappservice _supplierappservice; public suppliercontroller(isupplierappservice supplierappservice) { _supplierappservice = supplierappservice; } public async task<actionresult> editsuppliermodal(int moduleid) { var module = await _supplierappservice.get(new entitydto<int>(moduleid)); createupdatesupplierdto cusupplier = automapper.mapper.map<createupdatesupplierdto>(module); var model = new editsuppliermodalviewmodel { supplier = cusupplier }; return view("_editsuppliermodal", model); } } }

 

上一篇: C#环境配置

下一篇: C# 汉字转拼音