重构代码:移除Try/Catch模块,数据库操作使用影响行数判断是否成功
This commit is contained in:
parent
e556556e7c
commit
52427c77b2
|
@ -1,6 +1,5 @@
|
|||
using Bootstrap.Security;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -35,20 +34,12 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteDict(IEnumerable<int> value)
|
||||
{
|
||||
var ret = false;
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||
CacheCleanUtility.ClearCache(dictIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -67,8 +58,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = p.Id == 0 ?
|
||||
"Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" :
|
||||
"Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID";
|
||||
try
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
|
@ -76,15 +65,9 @@ namespace Bootstrap.DataAccess
|
|||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", p.Code));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Define", p.Define));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
ret = true;
|
||||
CacheCleanUtility.ClearCache(dictIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -98,22 +81,14 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
var ret = false;
|
||||
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
|
||||
try
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", dict.Name));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", dict.Code));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", dict.Category));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(dictIds: string.Empty);
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -127,8 +102,6 @@ namespace Bootstrap.DataAccess
|
|||
var ret = new List<BootstrapDict>();
|
||||
string sql = "select distinct Category from Dicts";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -136,8 +109,6 @@ namespace Bootstrap.DataAccess
|
|||
ret.Add(new BootstrapDict() { Category = (string)reader[0] });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Longbow.Cache;
|
||||
using Longbow.Data;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -31,8 +30,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select * from Groups";
|
||||
List<Group> groups = new List<Group>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -45,8 +42,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return groups;
|
||||
});
|
||||
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
||||
|
@ -58,21 +53,13 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteGroup(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(groupIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -88,22 +75,14 @@ namespace Bootstrap.DataAccess
|
|||
string sql = p.Id == 0 ?
|
||||
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
|
||||
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
|
||||
try
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupName", p.GroupName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -120,8 +99,6 @@ namespace Bootstrap.DataAccess
|
|||
List<Group> groups = new List<Group>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -135,8 +112,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return groups;
|
||||
}, RetrieveGroupsByUserIdDataKey);
|
||||
return ret;
|
||||
|
@ -182,8 +157,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -202,8 +177,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -217,8 +190,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return groups;
|
||||
}, RetrieveGroupsByRoleIdDataKey);
|
||||
}
|
||||
|
@ -261,8 +232,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Longbow.Cache;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -24,8 +23,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select top 1000 * from Logs";
|
||||
List<Log> logs = new List<Log>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -42,8 +39,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return logs;
|
||||
});
|
||||
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
|
||||
|
@ -56,20 +51,12 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteLog(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Logs where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||
CacheCleanUtility.ClearCache(logIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -83,8 +70,6 @@ namespace Bootstrap.DataAccess
|
|||
if (p == null) throw new ArgumentNullException("p");
|
||||
bool ret = false;
|
||||
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, GetDate(), @ClientIp, @ClientAgent, @RequestUrl)";
|
||||
try
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@CRUD", p.CRUD));
|
||||
|
@ -92,15 +77,9 @@ namespace Bootstrap.DataAccess
|
|||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientIp", p.ClientIp));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(logIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Data;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -27,21 +26,13 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteMenu(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -59,8 +50,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = p.Id == 0 ?
|
||||
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" :
|
||||
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID";
|
||||
try
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
|
@ -73,15 +62,9 @@ namespace Bootstrap.DataAccess
|
|||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Target", p.Target));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@IsResource", p.IsResource));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -96,8 +79,6 @@ namespace Bootstrap.DataAccess
|
|||
return CacheManager.GetOrAdd(key, k =>
|
||||
{
|
||||
var menus = new List<BootstrapMenu>();
|
||||
try
|
||||
{
|
||||
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
|
@ -113,8 +94,6 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return menus;
|
||||
}, RetrieveMenusByRoleIdDataKey);
|
||||
}
|
||||
|
@ -156,8 +135,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Longbow;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -27,8 +26,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = N'消息标签' and d.Define = 0 left join Dicts i on i.Category = N'头像地址' and i.Name = N'头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
|
||||
List<Message> messages = new List<Message>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
|
@ -52,8 +49,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return messages;
|
||||
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Longbow.Cache;
|
||||
using Longbow.Data;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -31,8 +30,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select * from Roles";
|
||||
List<Role> roles = new List<Role>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -45,8 +42,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return roles;
|
||||
});
|
||||
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
||||
|
@ -93,8 +88,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -110,8 +105,6 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
List<Role> roles = new List<Role>();
|
||||
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID";
|
||||
try
|
||||
{
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
|
@ -127,8 +120,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return roles;
|
||||
}, RetrieveRolesByUserIdDataKey);
|
||||
}
|
||||
|
@ -139,21 +130,13 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteRole(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(roleIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -169,22 +152,14 @@ namespace Bootstrap.DataAccess
|
|||
string sql = p.Id == 0 ?
|
||||
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
|
||||
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
|
||||
try
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleName", p.RoleName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -201,8 +176,6 @@ namespace Bootstrap.DataAccess
|
|||
List<Role> roles = new List<Role>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", menuId));
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -216,8 +189,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return roles;
|
||||
}, RetrieveRolesByMenuIdDataKey);
|
||||
return ret;
|
||||
|
@ -257,8 +228,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -276,8 +247,6 @@ namespace Bootstrap.DataAccess
|
|||
List<Role> roles = new List<Role>();
|
||||
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
|
@ -292,8 +261,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return roles;
|
||||
}, RetrieveRolesByGroupIdDataKey);
|
||||
}
|
||||
|
@ -339,8 +306,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Longbow.Cache;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -21,8 +20,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select top 1000 t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc";
|
||||
List<Task> tasks = new List<Task>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -40,8 +37,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return tasks;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue