重构代码:精简代码移除break语句,提高代码覆盖率

This commit is contained in:
Argo-Surface 2019-01-17 12:13:30 +08:00
parent edcfbeeebb
commit c20af5f655
7 changed files with 20 additions and 26 deletions

View File

@ -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>

View File

@ -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;
}

View File

@ -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>
///

View File

@ -63,8 +63,6 @@ namespace Bootstrap.Admin.Controllers.Api
case "user":
ret = MenuHelper.RetrieveMenus(User.Identity.Name);
break;
default:
break;
}
return ret;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -24,12 +24,14 @@ namespace Bootstrap.Admin.Models
public ProfilesModel(ControllerBase controller) : base(controller)
{
var host = controller.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment;
if (host == null) return;
var fileName = Path.Combine(host.WebRootPath, Icon.TrimStart('~', '/').Replace('/', '\\'));
if (File.Exists(fileName))
if (host != null)
{
Size = new FileInfo(fileName).Length;
FileName = Path.GetFileName(fileName);
var fileName = Path.Combine(host.WebRootPath, Icon.TrimStart('~', '/').Replace('/', '\\'));
if (File.Exists(fileName))
{
Size = new FileInfo(fileName).Length;
FileName = Path.GetFileName(fileName);
}
}
}
}