• ABP 软删除ISoftDelete


    一、简介

      ABP 的软删除是为了,在删除的时候,不是真正的删除数据,是为了保护数据。

    二、具体实现

      在 Core  层,我们需要这个实体去实现这个 ISoftDelete 接口。实现它的 public virtual bool IsDeleted { get; set; } 方法即可。

    namespace xxx.xxx.xxxxx
    {
        using Abp.Domain.Entities;
    
        /// <summary>
        /// 餐馆招聘 (Mg58Infos_RestaurantRecruitment) 实体
        /// </summary>
        public partial class RestaurantRecruitment : BasicInfo, ISoftDelete
        {
            public bool IsDeleted { get; set; }
        }
    }

     也可以实现 IFullAudited 方法,这个方法全一些。这个接口本身就继承了 ISoftDelete 接口。

    namespace xx.xxx.xxx
    {
        using Abp.Domain.Entities.Auditing;
        using xx.xx.xx;
        using System;
    
        /// <summary>
        /// 餐馆招聘 (Mg58Infos_RestaurantRecruitment) 实体
        /// </summary>
        public partial class RestaurantRecruitment : BasicInfo, IFullAudited
        {
            public long? LastModifierUserId { get; set ; }
            public DateTime? LastModificationTime { get ;set ; }
            public long? DeleterUserId { get; set; }
            public DateTime? DeletionTime { get ; set ; }
            public bool IsDeleted { get; set; }
        }
    }

      更改以后需要更新数据库就可以了。

    三、获取以删除的数据

      获取以删除的数据,我们需要用到如下的方法。加上这using 在查询的时间,系统会过滤掉对 isdeleted 这个字段的筛选,从而获取所有的数据。

    #pragma warning disable 1591    //  Ignore "Missing XML Comment" warning
    
    namespace Bit.xx.xxxxxx
    {
        using Abp.AutoMapper;
        using Abp.Domain.Repositories;
        using xx.xx.Mg58Infos;
        using xx.x;
        using x.x.Mg58Accounts.Dto;
        using System.Threading.Tasks;
        using Abp.Domain.Uow;
    
        /// <summary>
        /// 餐馆招聘绑定 服务
        /// </summary>
        public class RecruitmentBindUserAppService : AbpZeroTemplateAppServiceBase, IRecruitmentBindUserAppService
        {
    
            private readonly IRepository<RecruitmentBindUser, int> _recruitmentBindUserRepository;
            private readonly IRecruitmentBindUserManager _recruitmentBindUserManager;
            private readonly IRepository<RestaurantRecruitment, long> _restaurantRecruitmentRepository;
            private readonly IUnitOfWorkManager _unitOfWorkManager;
    
            public RecruitmentBindUserAppService(
            IUnitOfWorkManager unitOfWorkManager)
            {
                _unitOfWorkManager = unitOfWorkManager;
            }
            
            public async Task<RecruitmentBindUserEditDto> RecruitmentUserFilter(RecruitmentBindInfoFilterInput input)
            {
                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                {
    
                    //todo 此方法需要修改,获取发布的餐馆招聘数据将直接从单表获取
                    var recruitmentBindUser = await _recruitmentBindUserRepository.GetAsync(input.Id.Value);
    
                    //todo 修改消息是否已读
                    var recruitmentInfo = _restaurantRecruitmentRepository.Get(recruitmentBindUser.RecruitmentId);
                    
                    var q = recruitmentBindUser.MapTo<RecruitmentBindUserEditDto>();
                    return q;
    
                }
            }
    
            
        }
    }
  • 相关阅读:
    常用模块
    装饰器、生成器、迭代器
    java-异常处理
    java-运算符,IO输入输出,文件操作
    java-修饰符
    容器docker操作
    requirements模块使用
    pycharm的安装和使用
    python-scrapy框架
    生产环境django项目部署要点
  • 原文地址:https://www.cnblogs.com/gzbit-zxx/p/10641956.html
Copyright © 2020-2023  润新知