using Tiger.Model;
using Rhea.Common;
using Tiger.IBusiness;
using static Tiger.Business.Biz;
using Microsoft.AspNetCore.Http;
namespace Tiger.Business.MES
{
///
/// 车间
///
public partial class BizMesWs : IMES_WORKSHOP
{
///
/// 保存
///
///
///
public async Task SaveMesWs(MES_WORKSHOP ws)
{
var result = new ApiAction();
try
{
if (Db.Queryable().Where(x => x.WS_CODE == ws.WS_CODE && x.ID != ws.ID).Any())
{
result.IsSuccessed = false;
result.LocaleMsg = new($"车间已经存在,不能新增!");
return result;
}
var db = Db;
var dbTran = db.UseTran(() =>
{
var y = db.Storageable(ws)
.WhereColumns(t => new { t.WS_CODE, t.GHOST_ROW })
.ToStorage();
y.AsInsertable.ExecuteCommand();
y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
});
if (!dbTran.IsSuccess)
{
result.IsSuccessed = false;
result.Message = $"保存车间异常";
}
}
catch (Exception ex)
{
result.CatchExceptionWithLog(ex, "保存车间异常");
}
return await Task.FromResult(result);
}
///
/// 删除车间
///
///
///
public async Task DeleteMesWs(string wsId)
{
var result = new ApiAction();
try
{
//查询是否已经有车间在用
var db = Db;
var dbTran = db.UseTran(() =>
{
db.Deleteable().Where(x => x.ID == wsId).ExecuteCommand();
});
if (!dbTran.IsSuccess)
{
result.IsSuccessed = false;
result.LocaleMsg = new($"删除车间异常");
}
}
catch (Exception ex)
{
result.CatchExceptionWithLog(ex, "删除车间异常");
}
return await Task.FromResult(result);
}
}
}