refactor(PetaPoco): 字符串类型的主键为String.Empty保存失败

#Issue
link https://github.com/CollaboratingPlatypus/PetaPoco/issues/538
This commit is contained in:
Argo Zhang 2019-05-24 21:25:47 +08:00
parent 0391a20b57
commit 82417b68af
7 changed files with 11 additions and 1 deletions

View File

@ -63,6 +63,7 @@ namespace Bootstrap.DataAccess
{
if (RetrieveSystemModel() && RetrieveProtectedDicts().Any(m => m.Id == p.Id)) return true;
if (p.Id == string.Empty) p.Id = null;
var ret = DbContextManager.Create<Dict>().Save(p);
if (ret) CacheCleanUtility.ClearCache(dictIds: new List<string>());
return ret;

View File

@ -38,6 +38,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static bool Save(Group p)
{
if (p.Id == string.Empty) p.Id = null;
var ret = DbContextManager.Create<Group>().Save(p);
if (ret) CacheCleanUtility.ClearCache(groupIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
return ret;

View File

@ -24,6 +24,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static bool Save(Log log)
{
if (log.Id == string.Empty) log.Id = null;
log.LogTime = DateTime.Now;
return DbContextManager.Create<Log>().Save(log);
}

View File

@ -16,7 +16,11 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static bool Log(LoginUser user) => DbContextManager.Create<LoginUser>().Log(user);
public static bool Log(LoginUser user)
{
if (user.Id == string.Empty) user.Id = null;
return DbContextManager.Create<LoginUser>().Log(user);
}
/// <summary>
/// 查询指定页码登录日志

View File

@ -45,6 +45,7 @@ namespace Bootstrap.DataAccess
}
}
}
if (p.Id == string.Empty) p.Id = null;
var ret = DbContextManager.Create<Menu>().Save(p);
if (ret) CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
return ret;

View File

@ -14,6 +14,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static bool Save(ResetUser user)
{
if (user.Id == string.Empty) user.Id = null;
user.ResetTime = DateTime.Now;
return DbContextManager.Create<ResetUser>().Save(user);
}

View File

@ -68,6 +68,7 @@ namespace Bootstrap.DataAccess
var roles = new string[] { "Administrators", "Default" };
var rs = Retrieves().Where(r => roles.Any(rl => rl.Equals(r.RoleName, StringComparison.OrdinalIgnoreCase)));
if (rs.Any(r => r.Id == p.Id)) return true;
if (p.Id == string.Empty) p.Id = null;
var ret = DbContextManager.Create<Role>().Save(p);
if (ret) CacheCleanUtility.ClearCache(roleIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string> { p.Id });
return ret;