更改个人信息中的Description为不可为空字段

This commit is contained in:
Argo-Lenovo 2016-11-10 12:20:26 +08:00
parent 42d0c3e089
commit 7664e3180a
12 changed files with 41 additions and 38 deletions

View File

@ -66,6 +66,7 @@ namespace Bootstrap.Admin.Controllers
public bool Post([FromBody]User value)
{
value.ApprovedTime = DateTime.Now;
value.Description = string.Format("管理员{0}创建用户", User.Identity.Name);
return UserHelper.SaveUser(value);
}

View File

@ -21,7 +21,7 @@ namespace Bootstrap.Admin.Models
public QueryData<Group> RetrieveData()
{
// int limit, int offset, string name, string price, string sort, string order
var data = GroupHelper.RetrieveGroups(string.Empty);
var data = GroupHelper.RetrieveGroups();
if (!string.IsNullOrEmpty(GroupName))
{
data = data.Where(t => t.GroupName.Contains(GroupName));

View File

@ -20,9 +20,13 @@ namespace Bootstrap.Admin.Models
///
/// </summary>
public string OperateTimeEnd { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public QueryData<Log> RetrieveData()
{
var data = LogHelper.RetrieveLogs(string.Empty);
var data = LogHelper.RetrieveLogs();
if (!string.IsNullOrEmpty(OperateType))
{
data = data.Where(t => t.CRUD.ToString().Contains(OperateType));

View File

@ -21,7 +21,7 @@ namespace Bootstrap.Admin.Models
public QueryData<Role> RetrieveData()
{
// int limit, int offset, string name, string price, string sort, string order
var data = RoleHelper.RetrieveRoles(string.Empty);
var data = RoleHelper.RetrieveRoles();
if (!string.IsNullOrEmpty(RoleName))
{
data = data.Where(t => t.RoleName.Contains(RoleName));

View File

@ -21,7 +21,7 @@ namespace Bootstrap.Admin.Models
public QueryData<User> RetrieveData()
{
// int limit, int offset, string name, string price, string sort, string order
var data = UserHelper.RetrieveUsers(string.Empty);
var data = UserHelper.RetrieveUsers();
if (!string.IsNullOrEmpty(Name))
{
data = data.Where(t => t.UserName.Contains(Name));

View File

@ -1,4 +1,5 @@
using Longbow.Caching;
using Longbow;
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data;
using Longbow.ExceptionManagement;
@ -24,9 +25,9 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 查询所有群组信息
/// </summary>
/// <param name="tId"></param>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<Group> RetrieveGroups(string tId = null)
public static IEnumerable<Group> RetrieveGroups(int id = 0)
{
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveGroupsDataKey), key =>
{
@ -43,7 +44,7 @@ namespace Bootstrap.DataAccess
{
ID = (int)reader[0],
GroupName = (string)reader[1],
Description = (string)reader[2]
Description = LgbConvert.ReadValue(reader[2], string.Empty)
});
}
}
@ -51,7 +52,7 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); }
return Groups;
}, CacheSection.RetrieveDescByKey(RetrieveGroupsDataKey));
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase));
return id == 0 ? ret : ret.Where(t => id == t.ID);
}
/// <summary>
/// 删除群组信息
@ -87,7 +88,7 @@ namespace Bootstrap.DataAccess
if (p == null) throw new ArgumentNullException("p");
bool ret = false;
if (p.GroupName.Length > 50) p.GroupName.Substring(0, 50);
if (p.Description.Length > 500) p.Description.Substring(0, 500);
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 500) p.Description.Substring(0, 500);
string sql = p.ID == 0 ?
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
@ -97,7 +98,7 @@ namespace Bootstrap.DataAccess
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.ID, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupName", p.GroupName, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", p.Description, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccess.ToDBValue(p.Description), ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
CacheCleanUtility.ClearCache(groupIds: p.ID == 0 ? "" : p.ID.ToString());

View File

@ -27,9 +27,9 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 查询所有角色
/// </summary>
/// <param name="tId"></param>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRoles(string tId = null)
public static IEnumerable<Role> RetrieveRoles(int id = 0)
{
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, CacheSection.RetrieveIntervalByKey(RetrieveRolesDataKey), key =>
{
@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesDataKey));
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase));
return id == 0 ? ret : ret.Where(t => id == t.ID);
}
/// <summary>
/// 保存用户角色关系

View File

@ -1,4 +1,5 @@
using Longbow.Caching;
using Longbow;
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data;
using Longbow.ExceptionManagement;
@ -25,9 +26,9 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 查询所有用户
/// </summary>
/// <param name="pIds"></param>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<User> RetrieveUsers(string tId = null)
public static IEnumerable<User> RetrieveUsers(int id = 0)
{
string sql = "select ID, UserName, DisplayName, RegisterTime, ApprovedTime from Users Where ApprovedTime is not null";
var ret = CacheManager.GetOrAdd(RetrieveUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveUsersDataKey), key =>
@ -46,7 +47,7 @@ namespace Bootstrap.DataAccess
UserName = (string)reader[1],
DisplayName = (string)reader[2],
RegisterTime = (DateTime)reader[3],
ApprovedTime = (DateTime)reader[4]
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue)
});
}
}
@ -54,7 +55,7 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); }
return Users;
}, CacheSection.RetrieveDescByKey(RetrieveUsersDataKey));
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase));
return id == 0 ? ret : ret.Where(t => id == t.ID);
}
/// <summary>
/// 根据用户名查询用户
@ -127,17 +128,13 @@ namespace Bootstrap.DataAccess
{
if (p == null) throw new ArgumentNullException("p");
bool ret = false;
if (p.UserName.Length > 50)
p.UserName.Substring(0, 50);
if (p.UserName.Length > 50) p.UserName.Substring(0, 50);
p.PassSalt = LgbCryptography.GenerateSalt();
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
if (string.IsNullOrEmpty(p.Description))
p.Description=" ";
else if(p.Description.Length > 500)
p.Description.Substring(0, 500);
if (p.ID == 0 && p.Description.Length > 500) p.Description.Substring(0, 500);
string sql = p.ID == 0 ?
"Insert Into Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime,Description) Values (@UserName, @Password, @PassSalt, @DisplayName, GetDate(), @ApprovedTime,@Description)" :
"Update Users set UserName = @UserName, Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName,Description=@Description where ID = @ID";
"Insert Into Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime, Description) Values (@UserName, @Password, @PassSalt, @DisplayName, GetDate(), @ApprovedTime, @Description)" :
"Update Users set UserName = @UserName, Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @ID";
try
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
@ -148,7 +145,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", p.PassSalt, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", p.DisplayName, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApprovedTime", DBAccess.ToDBValue(p.ApprovedTime), ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", p.Description, ParameterDirection.Input));
if (p.ID == 0) cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", p.Description, ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
CacheCleanUtility.ClearCache(userIds: p.ID == 0 ? "" : p.ID.ToString());
@ -331,12 +328,12 @@ namespace Bootstrap.DataAccess
///
/// </summary>
/// <returns></returns>
public static bool RegisterUser(string userName, string displayName, string password,string description)
public static bool RegisterUser(string userName, string displayName, string password, string description)
{
//TODO未完成并通知管理员组有新用户注册需要批复。
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(description))
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(description))
return false;
return SaveUser(new User() { UserName = userName, DisplayName = displayName, Password = password,Description=description });
return SaveUser(new User() { UserName = userName, DisplayName = displayName, Password = password, Description = description });
}
}
}

View File

@ -17,7 +17,7 @@ namespace Bootstrap.DataAccess.Tests
public void IniInitialized()
{
Group = new Group() { GroupName = "_测试部门_", Description = "我是很厉害的测试部门" };
User = new User() { UserName = "_测试用户_", Password = "123", PassSalt = "123", DisplayName = "测试者", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now };
User = new User() { UserName = "_测试用户_", Password = "123", PassSalt = "123", DisplayName = "测试者", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试用户" };
Role = new Role() { RoleName = "_测试角色_", Description = "测试角色" };
}
@ -48,7 +48,7 @@ namespace Bootstrap.DataAccess.Tests
var group = groups.FirstOrDefault(g => g.GroupName == Group.GroupName);
group.Description = "我是测试部门";
Assert.IsTrue(GroupHelper.SaveGroup(group), string.Format("更新部门ID={0}操作失败请检查GroupHelper.SaveGroup方法", group.ID));
var ret = GroupHelper.RetrieveGroups(group.ID.ToString());
var ret = GroupHelper.RetrieveGroups(group.ID);
Assert.IsTrue(ret.Count() == 1, "带参数的GroupHelper.RetrieveGroups方法失败");
Assert.AreEqual(group.Description, ret.First().Description, string.Format("更新部门ID={0}操作失败请检查GroupHelper.SaveGroup方法", group.ID));
}

View File

@ -16,7 +16,7 @@ namespace Bootstrap.DataAccess.Tests
public void Initialized()
{
Role = new Role() { RoleName = "_测试角色_", Description = "这是一个测试角色", Checked = "0" };
User = new User() { UserName = "_测试用户_", Password = "111", PassSalt = "111", DisplayName = "_测试用户_", Checked = "0", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now };
User = new User() { UserName = "_测试用户_", Password = "111", PassSalt = "111", DisplayName = "_测试用户_", Checked = "0", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试用户" };
Group = new Group() { GroupName = "_测试部门_", Description = "这是一个测试部门", Checked = "0" };
}
[TestCleanup]
@ -38,7 +38,7 @@ namespace Bootstrap.DataAccess.Tests
var role = roles.FirstOrDefault(m => m.RoleName == Role.RoleName);
role.Description = "这是修改后的测试角色";
Assert.IsTrue(RoleHelper.SaveRole(role), string.Format("更新角色ID={0}操作失败请检查RoleHelper.SaveRole方法", role.ID));
var ret = RoleHelper.RetrieveRoles(role.ID.ToString());
var ret = RoleHelper.RetrieveRoles(role.ID);
Assert.IsTrue(ret.Count() == 1, "带参数的RoleHelper.RetrieveRoles方法调用失败");
Assert.AreEqual(role.Description, ret.First().Description, string.Format("更新角色ID={0}操作失败请检查RoleHelper.SaveRole方法", role.ID));
}

View File

@ -16,7 +16,7 @@ namespace Bootstrap.DataAccess.Tests
[TestInitialize]
public void Initialized()
{
User = new User() { UserName = "_测试用户_", Password = "123", PassSalt = "123", DisplayName = "测试者", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now };
User = new User() { UserName = "_测试用户_", Password = "123", PassSalt = "123", DisplayName = "测试者", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试" };
Role = new Role() { RoleName = "_测试角色_", Description = "测试角色" };
Group = new Group() { GroupName = "_测试部门_", Description = "测试部门" };
}
@ -49,7 +49,7 @@ namespace Bootstrap.DataAccess.Tests
var user = users.FirstOrDefault(u => u.UserName == User.UserName);
user.DisplayName = "测试者2号";
Assert.IsTrue(UserHelper.SaveUser(user), string.Format("更新用户ID={0}操作失败请检查UserHelper.SaveUser方法", user.ID));
var ret = UserHelper.RetrieveUsers(user.ID.ToString());
var ret = UserHelper.RetrieveUsers(user.ID);
Assert.IsTrue(ret.Count() == 1, "带参数的UserHelper.RetrieveUsers方法调用失败");
Assert.AreEqual(user.DisplayName, ret.First().DisplayName, string.Format("更新用户ID={0}操作失败请检查UserHelper.SaveUser方法", user.ID));
}

View File

@ -23,7 +23,7 @@ CREATE TABLE [dbo].[Users](
[DisplayName] [nvarchar](50) NOT NULL,
[RegisterTime] [datetime] NOT NULL,
[ApprovedTime] [datetime] NULL,
[Description] [nvarchar](500) NULL,
[Description] [nvarchar](500) NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[ID] ASC