public void updateUser(Server.Data.User User, out string resMsg)
{
try
{
var tempF = db.User.First(f => f.Id == User.Id);
var tempFT = db.UserType.First(ft => ft.Id == User.UserTypeId);
if (tempF!=null)
{
if (tempFT != null)
{
tempF.CreatorId = User.CreatorId;
tempF.UserName = User.UserName;
tempF.UserSize = User.UserSize;
tempF.UserType = tempFT;
tempF.LatestVersion = User.LatestVersion;
tempF.ModifierId = User.ModifierId;
tempF.ModifyDate = DateTime.Now.ToString();
db.SaveChanges();
resMsg = "Update User success";
}
else
{
resMsg = "Update User failure:UserType not found";
}
}
else
{
resMsg = "Update User failure:User not found";
}
}
catch (Exception ex)
{
resMsg = "Update User failure\n" + ex.ToString();
}
}
{
try
{
var tempF = db.User.First(f => f.Id == User.Id);
var tempFT = db.UserType.First(ft => ft.Id == User.UserTypeId);
if (tempF!=null)
{
if (tempFT != null)
{
tempF.CreatorId = User.CreatorId;
tempF.UserName = User.UserName;
tempF.UserSize = User.UserSize;
tempF.UserType = tempFT;
tempF.LatestVersion = User.LatestVersion;
tempF.ModifierId = User.ModifierId;
tempF.ModifyDate = DateTime.Now.ToString();
db.SaveChanges();
resMsg = "Update User success";
}
else
{
resMsg = "Update User failure:UserType not found";
}
}
else
{
resMsg = "Update User failure:User not found";
}
}
catch (Exception ex)
{
resMsg = "Update User failure\n" + ex.ToString();
}
}
注意外键约束,如果主键ID为自增长,注意将表的 IDentity 设为 on