Abp vNext micro business development service

Several were introduced before the abp vNext micro-services framework, development environment to build and vue element admin access front-end framework, implement user management role after basic functions can be started in business development in vue element admin herein, this will be described in detail how to develop service interface and implemented in the front page of abp vNext.

Business Interface Development

Service interface is aimed at business api interface, by abp vNext micro service and after service interfaces published front-end interface to acquire and interface development, so to achieve the front and rear end abp vNext separation of micro-services development.

From the start of entity

Abp vNext micro business development services framework uses the same architectural style and classic ddd ef core of code first mode, so all businesses are starting from the domain model (domain). Create a data dictionary model is as follows:

 

    public class DataDictionary : AuditedAggregateRoot<Guid>,ISoftDelete
    {
        [NotNull]
        public string Name { get; set; }

        public string Code { get; set; }

        [NotNull]
        public string FullName { get; set; }

        public Guid? CategoryID { get; set; }

        public string Notes { get; set; }

        public Guid? PID { get; set; }

[NotNull] public int SEQ { get; set; } public bool IsEdit { get; set; } public bool IsDeleted { get; set; } }

Join AbpDbContext:

public DbSet<DataDictionary> Dictionary { get; set; }

Construction of ef entities:

            builder.Entity<DataDictionary>(b =>
            {
                b.ToTable("Dictionary");

                b.ConfigureConcurrencyStamp();
                b.ConfigureExtraProperties();
                b.ConfigureAudited();

                b.Property(x => x.Name).IsRequired().HasMaxLength(ProductConsts.MaxNameLength);
                b.Property(x => x.Code).HasMaxLength(ProductConsts.MaxCodeLength);
                b.Property(x => x.FullName).IsRequired().HasMaxLength(ProductConsts.MaxFullNameLength);
                b.Property(x => x.Notes).HasMaxLength(ProductConsts.MaxNotesLength);
                b.Property(x => x.SEQ).IsRequired();

                b.HasIndex(q => q.Code);
                b.HasIndex(q => q.Name);
                b.HasIndex(q => q.CategoryID);
            });

Use ef migrate the database:

 Add-Migration
 Update-Database

Check whether the output log successful migration.

Create a data dictionary application service interface

Create a data dictionary and an interface dto as follows:

 

    public interface IDictionaryAppService : IApplicationService
    {
        Task<PagedResultDto<DictionaryDto>> GetAll(GetDictionaryInputDto input);

        Task<DictionaryDto> Get(Guid id);

        Task<DictionaryDto> Create(CreateDictionaryDto input);

        Task<DictionaryDto> Update(Guid id, UpdateDictionary input);

        Task Delete(List<Guid> ids);
    }
    public class CreateDictionaryDto
    {
        [Required]
        [StringLength(ProductConsts.MaxNameLength)]
        public string Name { get; set; }

        [StringLength(ProductConsts.MaxCodeLength)]
        public string Code { get; set; }

        public Guid? CategoryID { get; set; }

        [StringLength(ProductConsts.MaxNotesLength)]
        public string Notes { get; set; }

        public Guid? PID { get; set; }

        public int SEQ { get; set; }

        public bool IsEdit { get; set; }
    }
    public class DictionaryDto : AuditedEntityDto<Guid>
    {
        public string Name { get; set; }

        public string Code { get; set; }

        public string FullName { get; set; }

        public Guid? CategoryID { get; set; }

        public string Notes { get; set; }

        public Guid? PID { get; set; }

        public int SEQ { get; set; }

        public bool IsEdit { get; set; }
    }
    public class GetDictionaryInputDto: PagedAndSortedResultRequestDto
    {
        public string Filter { get; set; }

        public Guid CategoryID { get; set; }
    }
    public class UpdateDictionary
    {
        [StringLength(ProductConsts.MaxNotesLength)]
        public string Notes { get; set; }

        public Guid? PID { get; set; }

        public int SEQ { get; set; }
    }

Application services for data dictionary

Application layer is as follows:

 Inherit the base class:

public class DictionaryAppService : ApplicationService, IDictionaryAppService

Injection Warehousing:

        private readonly IRepository<DataDictionary, Guid> _repository;public DictionaryAppService(
            IRepository<DataDictionary, Guid> repository)
        {
            _repository = repository;
        }

Implement an interface

Add:

        public async Task<DictionaryDto> Create(CreateDictionaryDto input)
        {
            var existingDic = await _repository.FirstOrDefaultAsync(d => d.Name == input.Name);
            if (existingDic != null)
            {
                throw new BusinessException("名称: "+input.Name+"已存在");
            }var result = await _repository.InsertAsync(new DataDictionary
            {
                Id = GuidGenerator.Create(),
                Name = input.Name,
                Code = input.Code,
                FullName = input.Name,
                CategoryID = input.CategoryID,
                Notes = input.Notes,
                PID = input.PID,
                SEQ = input.SEQ,
                IsEdit=input.IsEdit
            });

            return ObjectMapper.Map<DataDictionary, DictionaryDto>(result);
        }

delete:

        public async Task Delete(List<Guid> ids)
        {
            foreach (var id in ids)
            {
                await _repository.DeleteAsync(id);
            }
        }

Inquire:

        public async Task<DictionaryDto> Get(Guid id)
        {
            var query = await _repository.GetAsync(id);
            var dto = ObjectMapper.Map<DataDictionary, DictionaryDto>(query);return dto;
        }

        public async Task<PagedResultDto<DictionaryDto>> GetAll(GetDictionaryInputDto input)
        {
            var query = _repository
                .Where(d => d.CategoryID == input.CategoryID)
                .WhereIf(!string.IsNullOrEmpty(input.Filter), d => d.Name.Contains(input.Filter) ||
                                                                   d.Code.Contains(input.Filter));

            var items = await query.OrderBy(input.Sorting ?? "SEQ")
                                        .Skip(input.SkipCount)
                                        .Take(input.MaxResultCount).ToListAsync();

            var totalCount = await query.CountAsync();
var dtos = ObjectMapper.Map<List<DataDictionary>, List<DictionaryDto>>(items);return new PagedResultDto<DictionaryDto>(totalCount, dtos);
        }

modify:

        public async Task<DictionaryDto> Update(Guid id, UpdateDictionary input)
        {var dic = await _repository.GetAsync(id);
            dic.Notes = input.Notes;
            dic.SEQ = input.SEQ;

            return ObjectMapper.Map<DataDictionary, DictionaryDto>(dic);
        }

Permission to increase the data dictionary

Competence

ProductManagementPermissions increased static class DataDictionary:

        public static class DataDictionary
        {
            public const string Default = BasicDataManagement + ".DataDictionary";
            public const string Delete = Default + ".Delete";
            public const string Update = Default + ".Update";
            public const string Create = Default + ".Create";
        }

Construction permissions

ProductManagementPermissionDefinitionProvider increase dataDictionary:

            var dataDictionary = basicDataManagementGroup.AddPermission(ProductManagementPermissions.DataDictionary.Default, L("DataDictionary"));
            dataDictionary.AddChild(ProductManagementPermissions.DataDictionary.Create, L("Permission:Create"));
            dataDictionary.AddChild(ProductManagementPermissions.DataDictionary.Delete, L("Permission:Delete"));
            dataDictionary.AddChild(ProductManagementPermissions.DataDictionary.Update, L("Permission:Edit"));

After the increase, respectively, plus the complete rights filters in the data dictionary application service

[Authorize(ProductManagementPermissions.DataDictionary.Default)]
[Authorize(ProductManagementPermissions.DataDictionary.Create)]
[Authorize(ProductManagementPermissions.DataDictionary.Delete)]
[Authorize(ProductManagementPermissions.DataDictionary.Update)]

Data Dictionary Mapping DTO

ProductManagementApplicationAutoMapperProfile increase in the data dictionary model -Dto map:

          CreateMap<DataDictionary, DictionaryDto>();

Data Dictionary web api realization

abp vNext not used in the original application services dynamically api, api now need to implement in the controller

    [RemoteService]
    [Area("basicData")]
    [Route("api/basicData/dataDictionary")]
    public class DataDictionaryController : AbpController, IDictionaryAppService
    {
        private readonly IDictionaryAppService _dictionaryAppService;

        public DataDictionaryController(IDictionaryAppService dictionaryAppService)
        {
            _dictionaryAppService = dictionaryAppService;
        }

        [HttpPost]
        public Task<DictionaryDto> Create(CreateDictionaryDto input)
        {
            return _dictionaryAppService.Create(input);
        }

        [HttpPost]
        [Route("Delete")]
        public Task Delete(List<Guid> ids)
        {
            return _dictionaryAppService.Delete(ids);
        }

        [HttpGet]
        [Route("{id}")]
        public Task<DictionaryDto> Get(Guid id)
        {
            return _dictionaryAppService.Get(id);
        }

        [HttpGet]
        [Route("all")]
        public Task<PagedResultDto<DictionaryDto>> GetAll(GetDictionaryInputDto input)
        {
            return _dictionaryAppService.GetAll(input);
        }

        [HttpPut]
        [Route("{id}")]
        public Task<DictionaryDto> Update(Guid id, UpdateDictionary input)
        {
            return _dictionaryAppService.Update(id, input);
        }
    }

to sum up

Here the data dictionary to single-sheet business has been developed, the project start to see swagger documentation can understand interface information, and next will continue to introduce abp vNext business front-end implementation.

Guess you like

Origin www.cnblogs.com/william-xu/p/11535246.html