Abp Add a new interface (extended underlying interface)

In https://aspnetboilerplate.com/Templates  After creating the project, Download Vs2019 open (vs2017 does not support netcore3.0) is structured as follows:

One,

 

2、

Class Code codemapping new entity in the xx.core 

 

 

 

 3、

 The new storage interface xx.core

4, to achieve the storage in xx.EntityFrameWork

 

Do not forget to make the following settings in the project context, it would not produce a corresponding table structure when performing add-migration and update-database 

 

 

 

 

 public class CodeMappingRepository:WuMingRepositoryBase<CodeMapping,int>,ICodeMappingRepository
    {
        public CodeMappingRepository(IDbContextProvider<WuMingDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public int Account()
        {
            throw new NotImplementedException();
        }
    }
public class CodeRepository :WuMingRepositoryBase<Code,int>,ICodeRepository
    {
        public CodeRepository(IDbContextProvider<WuMingDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
    }

 

5 .在xx.Application 定义Ixxservice 和实现实现接口

定义和实现:

 

ICodeAppService
public interface ICodeAppService: IApplicationService
    {
        List<Code> GetCodes();

        void UpdateCode(Code entity);

        void CreateCode(Code entity);

        void DeleteCode(int Id);
    }

CodeAppService:

  [AbpAllowAnonymous]
    public class CodeAppService :WuMingAppServiceBase, ICodeAppService
    {

        ICodeRepository _CodeRepository;
        ICodeMappingRepository _CodeMappingRepository;


        public CodeAppService(ICodeRepository CodeRepository, ICodeMappingRepository CodeMappingRepository) 
        {
            _CodeRepository = CodeRepository;
            _CodeMappingRepository = CodeMappingRepository;
        }

        public void CreateCode(Code entity)
        {
            Logger.Info($"Created a User for entity at:{DateTime.Now}");
            try
            {
                _CodeRepository.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
        }

        public void DeleteCode(int Id)
        {
            Logger.Info($"Created a User for entity at:{DateTime.Now}");
            try
            {
               // _CodeRepository.Delete(new Code() { Id = Id });

            }
            catch (Exception ex)
            {

                Logger.Error(ex.ToString());
            }

        }

        public List<Code> GetCodes()
        {
            Logger.Info($"Created a User for entity at:{DateTime.Now}");
            try
            {
                //return _CodeRepository.GetAll().ToList();
                return null;
            }
            catch (Exception ex)
            {

                throw;
            }
        }

        public void UpdateCode(Code entity)
        {
            Logger.Info($"Created a User for entity at:{DateTime.Now}");
            try
            {
                // _CodeRepository.Update(entity);
              

            }
            catch (Exception ex)
            {

                Logger.Error(ex.ToString());
            }
        }
    }

6.设置项目启动项: F5 就可以看到api接口地址及接口描述 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/yanwuming/p/12006816.html