服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2 天以前 3ab68d4877acffcb9677ecf369e15210e5db6981
Tiger.Business/DbBase.cs
@@ -3,6 +3,7 @@
using Rhea.Common;
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
@@ -874,5 +875,44 @@
        }
        #endregion 执行SQL
        #region 先删除后新增
        /// <summary>
        /// 删除完更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public new async Task<ApiAction> AddAfterDeleteAsync<T>(QueryAble<T> query) where T : class, new()
        {
            var action = new ApiAction();
            try
            {
                //保存到数据库
                var db = Business.Biz.Db;
                var dbTran = db.UseTran(() =>
                {
                    var dbres = !query.where.IsNullOrEmpty() ? db.Deleteable<T>().Where(query.where).ExecuteCommand() : db.Deleteable<T>().ExecuteCommand();
                    if (query.Items.Count > 0)
                    {
                        db.Insertable<T>(query.Items).ExecuteCommand();
                    }
                });
                if (!dbTran.IsSuccess)
                {
                    action.GetResponse().CatchExceptionWithLog(dbTran.ErrorException, $"作业保存到数据库异常");
                }
                action.Message = $"Delete {typeof(T).Name} entity by where and add list in database success";
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"Delete {typeof(T).Name} entity by where and add list in database exception");
            }
            return action;
        }
        #endregion
    }//endClass
}