You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
3 weeks ago
|
using SqlSugar;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace ReZero.SuperAPI
|
||
|
{
|
||
|
internal class InsertObject: CommonDataService, IDataService
|
||
|
{
|
||
|
public async Task<object> ExecuteAction(DataModel dataModel)
|
||
|
{
|
||
|
var db = App.GetDbTableId(dataModel.TableId) ?? App.Db;
|
||
|
var type = await EntityGeneratorManager.GetTypeAsync(dataModel.TableId);
|
||
|
base.InitDb(type, db);
|
||
|
base.InitData(type, db, dataModel);
|
||
|
this.SetDefaultValue(dataModel, db, type);
|
||
|
if (dataModel.ResultType == SqlResultType.IdNumber)
|
||
|
{
|
||
|
var idNumber = await db.InsertableByObject(dataModel.Data).ExecuteReturnIdentityAsync();
|
||
|
base.ClearAll(dataModel);
|
||
|
return idNumber;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await db.InsertableByObject(dataModel.Data).ExecuteCommandAsync();
|
||
|
base.ClearAll(dataModel);
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void SetDefaultValue(DataModel dataModel, ISqlSugarClient db, Type type)
|
||
|
{
|
||
|
if (EntityMappingService.IsAnyDefaultValue(dataModel))
|
||
|
{
|
||
|
dataModel.Data = EntityMappingService.GetDataByDefaultValueParameters(type, db, dataModel);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|