You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/DB/Service/UpdateLogService.cs

58 lines
1.6 KiB
C#

2 weeks ago
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Forms.VisualStyles;
using DB.Dto;
using DB.Entity;
using Tool;
namespace DB.Service
{
public class UpdateLogService
{
public bool AddOrUpdateLog(UserDto user,string address,uint value)
{
UpdateLog log = new UpdateLog
{
ID = SnowflakeFactory.NewId,
PointName = address,
CreateDate = DateTime.Now,
CreateUserId = user.Id.ToString(),
CreateUserName = user.UserName,
LastModifyUserId = "",
LastModifyUserName = "",
LastModifyDate = DateTime.Now
};
using (var dbContext = DbFactory.GetContext)
{
var firstOrDefault = dbContext.Query<UpdateLog>()
.Where(x=>x.PointName==address)
.OrderByDesc(x=>x.ID).FirstOrDefault();
if (firstOrDefault != null)
{
if (firstOrDefault.NewValue != value.ToString())
{
log.OldValue = firstOrDefault.NewValue;
log.NewValue = value.ToString();
dbContext.Insert(log);
}
}
else
{
log.OldValue = "";
log.NewValue = value.ToString();
dbContext.Insert(log);
}
}
return true;
}
}
}