重构代码:精简代码移除break语句,提高代码覆盖率
This commit is contained in:
parent
edcfbeeebb
commit
c20af5f655
|
@ -35,10 +35,11 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
public IEnumerable<string> Post()
|
||||
{
|
||||
var filePath = Path.Combine(AppContext.BaseDirectory, "Error");
|
||||
if (!Directory.Exists(filePath)) return new List<string>();
|
||||
return Directory.GetFiles(filePath)
|
||||
return Directory.Exists(filePath)
|
||||
? Directory.GetFiles(filePath)
|
||||
.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>
|
||||
|
|
|
@ -74,8 +74,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
case "role":
|
||||
ret = GroupHelper.RetrievesByRoleId(id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -99,8 +97,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
case "role":
|
||||
ret = GroupHelper.SaveByRoleId(id, groupIds);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -25,14 +25,15 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
[HttpPost]
|
||||
public string Post([FromBody]JObject value)
|
||||
{
|
||||
string token = null;
|
||||
dynamic user = value;
|
||||
string userName = user.userName;
|
||||
string password = user.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>
|
||||
///
|
||||
|
|
|
@ -63,8 +63,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
case "user":
|
||||
ret = MenuHelper.RetrieveMenus(User.Identity.Name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -46,8 +46,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
case "menu":
|
||||
ret = RoleHelper.RetrievesByMenuId(id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret.Select(m => new { m.Id, m.Checked, m.RoleName, m.Description });
|
||||
}
|
||||
|
@ -73,8 +71,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
case "menu":
|
||||
ret = RoleHelper.SavaByMenuId(id, roleIds);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -58,21 +58,23 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
[HttpPost("{id}")]
|
||||
public IEnumerable<object> Post(string id, [FromQuery]string type)
|
||||
{
|
||||
IEnumerable<object> ret = null;
|
||||
switch (type)
|
||||
{
|
||||
case "role":
|
||||
return UserHelper.RetrievesByRoleId(id).Select(p => new
|
||||
ret = UserHelper.RetrievesByRoleId(id).Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.DisplayName,
|
||||
p.UserName,
|
||||
p.Checked
|
||||
});
|
||||
break;
|
||||
case "group":
|
||||
return UserHelper.RetrievesByGroupId(id).ToList();
|
||||
default:
|
||||
return null;
|
||||
ret = UserHelper.RetrievesByGroupId(id);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
/// 前台User View调用,新建/更新用户
|
||||
|
@ -114,8 +116,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
case "group":
|
||||
ret = UserHelper.SaveByGroupId(id, userIds);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ namespace Bootstrap.Admin.Models
|
|||
public ProfilesModel(ControllerBase controller) : base(controller)
|
||||
{
|
||||
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))
|
||||
{
|
||||
|
@ -33,4 +34,5 @@ namespace Bootstrap.Admin.Models
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue