重构代码:精简代码移除break语句,提高代码覆盖率
This commit is contained in:
parent
edcfbeeebb
commit
c20af5f655
|
@ -35,10 +35,11 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
public IEnumerable<string> Post()
|
public IEnumerable<string> Post()
|
||||||
{
|
{
|
||||||
var filePath = Path.Combine(AppContext.BaseDirectory, "Error");
|
var filePath = Path.Combine(AppContext.BaseDirectory, "Error");
|
||||||
if (!Directory.Exists(filePath)) return new List<string>();
|
return Directory.Exists(filePath)
|
||||||
return Directory.GetFiles(filePath)
|
? Directory.GetFiles(filePath)
|
||||||
.Where(f => Path.GetExtension(f).Equals(".log", StringComparison.OrdinalIgnoreCase))
|
.Where(f => Path.GetExtension(f).Equals(".log", StringComparison.OrdinalIgnoreCase))
|
||||||
.Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s);
|
.Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s)
|
||||||
|
: Enumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -74,8 +74,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
case "role":
|
case "role":
|
||||||
ret = GroupHelper.RetrievesByRoleId(id);
|
ret = GroupHelper.RetrievesByRoleId(id);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -99,8 +97,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
case "role":
|
case "role":
|
||||||
ret = GroupHelper.SaveByRoleId(id, groupIds);
|
ret = GroupHelper.SaveByRoleId(id, groupIds);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,14 +25,15 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public string Post([FromBody]JObject value)
|
public string Post([FromBody]JObject value)
|
||||||
{
|
{
|
||||||
|
string token = null;
|
||||||
dynamic user = value;
|
dynamic user = value;
|
||||||
string userName = user.userName;
|
string userName = user.userName;
|
||||||
string password = user.password;
|
string password = user.password;
|
||||||
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password))
|
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password))
|
||||||
{
|
{
|
||||||
return BootstrapAdminJwtTokenHandler.CreateToken(userName);
|
token = BootstrapAdminJwtTokenHandler.CreateToken(userName);
|
||||||
}
|
}
|
||||||
return null;
|
return token;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
|
|
@ -63,8 +63,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
case "user":
|
case "user":
|
||||||
ret = MenuHelper.RetrieveMenus(User.Identity.Name);
|
ret = MenuHelper.RetrieveMenus(User.Identity.Name);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
case "menu":
|
case "menu":
|
||||||
ret = RoleHelper.RetrievesByMenuId(id);
|
ret = RoleHelper.RetrievesByMenuId(id);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret.Select(m => new { m.Id, m.Checked, m.RoleName, m.Description });
|
return ret.Select(m => new { m.Id, m.Checked, m.RoleName, m.Description });
|
||||||
}
|
}
|
||||||
|
@ -73,8 +71,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
case "menu":
|
case "menu":
|
||||||
ret = RoleHelper.SavaByMenuId(id, roleIds);
|
ret = RoleHelper.SavaByMenuId(id, roleIds);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,21 +58,23 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
[HttpPost("{id}")]
|
[HttpPost("{id}")]
|
||||||
public IEnumerable<object> Post(string id, [FromQuery]string type)
|
public IEnumerable<object> Post(string id, [FromQuery]string type)
|
||||||
{
|
{
|
||||||
|
IEnumerable<object> ret = null;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case "role":
|
case "role":
|
||||||
return UserHelper.RetrievesByRoleId(id).Select(p => new
|
ret = UserHelper.RetrievesByRoleId(id).Select(p => new
|
||||||
{
|
{
|
||||||
p.Id,
|
p.Id,
|
||||||
p.DisplayName,
|
p.DisplayName,
|
||||||
p.UserName,
|
p.UserName,
|
||||||
p.Checked
|
p.Checked
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
case "group":
|
case "group":
|
||||||
return UserHelper.RetrievesByGroupId(id).ToList();
|
ret = UserHelper.RetrievesByGroupId(id);
|
||||||
default:
|
break;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 前台User View调用,新建/更新用户
|
/// 前台User View调用,新建/更新用户
|
||||||
|
@ -114,8 +116,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
case "group":
|
case "group":
|
||||||
ret = UserHelper.SaveByGroupId(id, userIds);
|
ret = UserHelper.SaveByGroupId(id, userIds);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,14 @@ namespace Bootstrap.Admin.Models
|
||||||
public ProfilesModel(ControllerBase controller) : base(controller)
|
public ProfilesModel(ControllerBase controller) : base(controller)
|
||||||
{
|
{
|
||||||
var host = controller.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment;
|
var host = controller.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment;
|
||||||
if (host == null) return;
|
if (host != null)
|
||||||
var fileName = Path.Combine(host.WebRootPath, Icon.TrimStart('~', '/').Replace('/', '\\'));
|
|
||||||
if (File.Exists(fileName))
|
|
||||||
{
|
{
|
||||||
Size = new FileInfo(fileName).Length;
|
var fileName = Path.Combine(host.WebRootPath, Icon.TrimStart('~', '/').Replace('/', '\\'));
|
||||||
FileName = Path.GetFileName(fileName);
|
if (File.Exists(fileName))
|
||||||
|
{
|
||||||
|
Size = new FileInfo(fileName).Length;
|
||||||
|
FileName = Path.GetFileName(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue