using Nirvana.Common;
using Nirvana.Common.ApiBase;
using Nirvana.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using YBDevice.Entity;
namespace YBDevice.NApi.DBServices
{
///
/// 设备管理
///
public partial class DeviceApp : Repository
{
///
/// 设备注册
///
/// 设备资料
///
public async Task RegAsync(YB_Device yB_Device)
{
using (var dbClient = ReadDbContext.GetInstance())
{
yB_Device.Ecode = yB_Device.Ecode.ToStr();
yB_Device.FacCode = yB_Device.FacCode.ToStr();
if (await dbClient.Queryable().AnyAsync(x => x.Ecode == yB_Device.Ecode))
{
return new ResultInfo(ResultState.FAIL, "此机器码已存在");
}
if (await dbClient.Queryable().AnyAsync(x => x.FacCode == yB_Device.FacCode))
{
return new ResultInfo(ResultState.FAIL, "此序列号已存在");
}
//注册设备
yB_Device.Name = yB_Device.FacCode;
yB_Device.BusinessId = 0;
yB_Device.Status = (int)DeviceStatus.UnActive;
yB_Device.Remark = string.Empty;
yB_Device.CreateTime = DateTime.Now;
await dbClient.Insertable(yB_Device).ExecuteCommandAsync();
return new ResultInfo(ResultState.SUCCESS, "注册成功");
}
}
}
}