/// <summary> /// 逻辑删除 /// </summary> /// <param name="info">要删除的数据id</param> /// <param name="logonInfo">登录的用户信息</param> /// <returns></returns> public ResultView Delete(T info, TokenLogonInfo logonInfo) { if (info == null) { throw ApiException.EmptyData("无法找到要删除的数据"); } string id = info.Id.ToString(); _logger.LogTrace($"逻辑删除 ==> 类型为:[{typeof(T).FullName}]\t删除ID为:[{id}]"); try { // 判断对应数据是否可以删除. DeleteRemoveCheck(info); OnDeleteRemoveCheck?.Invoke(info, logonInfo); DeleteCheck(info); OnDeleteCheck?.Invoke(info, logonInfo); // 逻辑删除的前置操作 DeleteRemoving(info, logonInfo); Deleting(info, logonInfo); // 逻辑删除前置事件处理 OnDeleting?.Invoke(info, logonInfo); // 设置逻辑删除状态 info.UpdateDate = DateTime.Now; info.UpdaterId = logonInfo.Id; info.UpdaterName = logonInfo.Name; info.IsDelete = true; // 持久化数据 _Dal.UpdateObject(info); // 逻辑删除的后置处理 Deleted(info, logonInfo); DeleteRemoved(info, logonInfo); // 逻辑删除后置事件处理 OnDeleted?.Invoke(info, logonInfo); // 返回保存结果 return(ResultView.Success(id)); } catch (Exception ex) { _logger.LogError(ex, $"逻辑删除异常 ==> 类型为:[{typeof(T).FullName}]\t删除ID为:[{id}]\r\n删除对象:[{info.ToJson()}]"); throw; } }
/// <summary> /// 取消逻辑删除 /// </summary> /// <param name="info"></param> /// <param name="logonInfo"></param> /// <returns></returns> public virtual ResultView UnDelete(T info, TokenLogonInfo logonInfo) { // 判断id是否有对应数据 if (info == null) { throw ApiException.EmptyData("无法找到要还原的数据"); } string id = info.Id.ToString(); _logger.LogTrace($"还原删除数据 ==> 类型为:[{typeof(T).FullName}]\t还原ID为:[{id}]"); try { // 取消逻辑删除的前置操作 UnDeleting(info, logonInfo); // 取消逻辑删除的前置事件处理 OnUnDeleting?.Invoke(info, logonInfo); // 取消删除状态 info.UpdateDate = DateTime.Now; info.UpdaterId = logonInfo.Id; info.UpdaterName = logonInfo.Name; info.IsDelete = false; // 持久化数据 _Dal.UpdateObject(info); // 还原的后置操作 UnDeleted(info, logonInfo); // 取消还原删除的后置事件处理 OnUnDeleted?.Invoke(info, logonInfo); // 返回保存结果 return(ResultView.Success(id)); } catch (Exception ex) { _logger.LogError(ex, $"还原删除数据异常 ==> 类型为:[{typeof(T).FullName}]\t还原ID为:[{id}]\r\n还原对象:[{info.ToJson()}]"); throw; } }
/// <summary> /// 物理删除 /// </summary> /// <param name="info"></param> /// <param name="logonInfo"></param> /// <returns></returns> public ResultView Remove(T info, TokenLogonInfo logonInfo) { if (info == null) { throw ApiException.EmptyData("无法找到要删除的数据"); } string id = info.Id.ToString(); _logger.LogTrace($"物理删除 ==> 类型为:[{typeof(T).FullName}]\t删除ID为:[{id}]"); try { // 判断对应数据是否可以删除. DeleteRemoveCheck(info); OnDeleteRemoveCheck?.Invoke(info, logonInfo); RemoveCheck(info); OnRemoveCheck?.Invoke(info, logonInfo); // 物理删除的前置操作 DeleteRemoving(info, logonInfo); Removing(info, logonInfo); // 物理删除时的前置事件处理 OnRemoving?.Invoke(info, logonInfo); // 持久化数据 _Dal.RemoveObject(info); // 物理删除的后置处理 Removed(info, logonInfo); DeleteRemoved(info, logonInfo); // 物理删除时的后置事件处理 OnRemoved?.Invoke(info, logonInfo); // 返回保存结果 return(ResultView.Success(info.Id.ToString())); } catch (Exception ex) { _logger.LogError(ex, $"物理删除异常 ==> 类型为:[{typeof(T).FullName}]\t删除ID为:[{id}]]\r\n删除对象为:[{info.ToJson()}]"); throw; } }