abp (net core) + easyui + efcore implemented Warehouse Management System - WEBAPI implemented CURD (XI)

abp (net core) + easyui + efcore implement warehouse management system directory

abp (net core) + easyui + efcore implement warehouse management system --ABP general introduction (a)

abp (net core) + easyui + efcore implement Warehouse Management System - Solutions Introduction (b)

abp (net core) + easyui + efcore implement warehouse management system - the domain layer created entity (c)

 abp (net core) + easyui + efcore implement warehouse management system - Define and implement storage (IV)

abp (net core) + easyui + efcore implement Warehouse Management System - Create application services (five)

abp (net core) + easyui + efcore implemented warehouse management system - to achieve the presentation layer of the CRUD controller (vi)

abp (net core) + easyui + efcore implement Warehouse Management System - the presentation layer to achieve CRUD the list view (seven)

abp (net core) + easyui + efcore implement Warehouse Management System - the presentation layer to achieve the CRUD CRUD view (eight)

abp (net core) + easyui + efcore implement Warehouse Management System - the presentation layer to achieve CRUD and test the menu (IX)

abp (net core) + easyui + efcore implement Warehouse Management System - Multilingual (X)

 

      By abp (net core) + easyui + efcore implemented warehouse management system - to achieve the presentation layer of the CRUD controllers (VI) to abp (net core) + easyui + efcore implemented warehouse management system - to achieve the presentation layer CRUD the menu and test (nine) study of four articles, we use conventional implementations ASP.NET Core Mvc achieved CURD operation of the database. ABP has its default implementation CRUD way. We can look at "ABP.TPLMS.Web.Mvc" project "Views \ Users" of the relevant code, you can look at is how to achieve ABP default user additions and deletions to change search of information. We found that deletions of user information in the ABP change search operation is achieved through inheritance AsyncCrudAppService CURD this class, the front page is achieved through additions and deletions to change search WEB API javascript call. Of course, there is a synchronous operation class CrudAppService, to achieve synchronous operation CURD this class through inheritance. For both classes of difference is that AsyncCrudAppService CrudAppService asynchronously. ABP as a development framework to achieve a solution to this general function CRUD by two or more base classes. In the next few articles, we are going through to achieve operating CURD AsyncCrudAppService inherit this class to achieve vendor additions and deletions to the information at the front end by calling WebAPI change search function.

          First look at AsyncCrudAppService and CrudAppService these two classes specific functions provided.

          First of all, these two classes inherit from CrudAppServiceBase class. 1, FIG.

 

figure 1

 

figure 2

     Secondly, these two classes provide Create, Delete, Update, Get, GetAll, GetEntityById method.

      第三,CrudAppServiceBase类提供了有关于权限(xxxPermissionName属性和CheckxxxPermission方法)的属性和方法,关于分页(ApplyPaging)的方法,关于排序(ApplySorting)方法,关于查询条件(CreateFilteredQuery)的方法,关于对象映射(MapToxxx)的方法。如下图。

        接下来我们来通过实现一个供应商信息的管理功能来学习一下这种方式实现增删改查功能。我会通过几篇文章来一步一步来实现这个供应商管理的功能。

 一、创建Supplier实体

        1. 在Visual Studio 2017的“解决方案资源管理器”中,右键单击“ABP.TPLMS.Core”项目的“Entitys”文件夹,在弹出菜单中选择“添加” --> “类”。 将类命名为 Supplier,然后选择“添加”。

        2.创建Supplier类继承自Entity<int>,通过实现审计模块中的IHasCreationTime来实现保存创建时间。代码如下:

using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Abp.Timing;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text; 

namespace ABP.TPLMS.Entitys
{
    public class Supplier : Entity<int>, IHasCreationTime
    {
        public const int MaxLength = 255;
        public Supplier()
        {

            this.Address = string.Empty;
            this.Name = string.Empty;
            this.Email = string.Empty;
            this.Code = string.Empty;

            this.Sex = 0;
            this.LinkName = string.Empty;
            this.Status = 0;
            this.Tel = string.Empty;
            this.Mobile = string.Empty;
                       this.UserId = 0;

            CreationTime = Clock.Now;
        } 

        [Required]
        [StringLength(50)]
        public string Code { get; set; }

        [Required]
        [StringLength(MaxLength)]
        public string Name { get; set; }

        [StringLength(MaxLength)]
        public string Address { get; set; }

        [Required]
        [StringLength(MaxLength)]

        public string Email { get; set; }      

        [StringLength(MaxLength)]
        public string LinkName { get; set; }
        public int Sex { get; set; }    

        [Required]
        [StringLength(MaxLength)]
        public string Tel { get; set; }
        [StringLength(MaxLength)]
        public string Mobile { get; set; }
        public int Status { get; set; }
        public int UserId { get; set; }
        public DateTime CreationTime { get; set; } 
    }
}

      3.定义好实体之后,我们去“ABP.TPLMS.EntityFrameworkCore”项目中的“TPLMSDbContext”类中定义实体对应的DbSet,以应用Code First 数据迁移。添加以下代码

using Microsoft.EntityFrameworkCore;
using Abp.Zero.EntityFrameworkCore;
using ABP.TPLMS.Authorization.Roles;
using ABP.TPLMS.Authorization.Users;
using ABP.TPLMS.MultiTenancy;
using ABP.TPLMS.Entitys; 

namespace ABP.TPLMS.EntityFrameworkCore
{
    public class TPLMSDbContext : AbpZeroDbContext<Tenant, Role, User, TPLMSDbContext>
    {
        /* Define a DbSet for each entity of the application */     

        public TPLMSDbContext(DbContextOptions<TPLMSDbContext> options)
            : base(options)

        {
        }

        public DbSet<Module> Modules { get; set; }
        public DbSet<Supplier> Suppliers { get; set; }
    }
}

     4.从菜单中选择“工具->NuGet包管理器器—>程序包管理器控制台”菜单。

     5. 在PMC中,默认项目选择EntityframeworkCore对应的项目后。输入以下命令:Add-Migration AddEntitySupplier,创建迁移。如下图。

 

     6. 在上面的命令执行完毕之后,创建成功后,会在Migrations文件夹下创建时间_AddEntitySupplier格式的类文件,这些代码是基于DbContext指定的模型。如下图。

 

     7.在程序包管理器控制台,输入Update-Database,回车执行迁移。如下图。

 

     8.执行成功后,查看数据库,Suppliers表创建成功。

 

 

Guess you like

Origin www.cnblogs.com/chillsrc/p/11269737.html