diff --git a/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs b/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs index 582617ad..1a89ca6a 100644 --- a/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs +++ b/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs @@ -35,10 +35,11 @@ namespace Bootstrap.Admin.Controllers.Api public IEnumerable Post() { var filePath = Path.Combine(AppContext.BaseDirectory, "Error"); - if (!Directory.Exists(filePath)) return new List(); - 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(); } /// diff --git a/Bootstrap.Admin/Controllers/Api/GroupsController.cs b/Bootstrap.Admin/Controllers/Api/GroupsController.cs index 482b66a9..9bb9faa9 100644 --- a/Bootstrap.Admin/Controllers/Api/GroupsController.cs +++ b/Bootstrap.Admin/Controllers/Api/GroupsController.cs @@ -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; } diff --git a/Bootstrap.Admin/Controllers/Api/LoginController.cs b/Bootstrap.Admin/Controllers/Api/LoginController.cs index d4a3a258..ad81582f 100644 --- a/Bootstrap.Admin/Controllers/Api/LoginController.cs +++ b/Bootstrap.Admin/Controllers/Api/LoginController.cs @@ -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; } /// /// diff --git a/Bootstrap.Admin/Controllers/Api/MenusController.cs b/Bootstrap.Admin/Controllers/Api/MenusController.cs index c38dc5a5..b619b3c9 100644 --- a/Bootstrap.Admin/Controllers/Api/MenusController.cs +++ b/Bootstrap.Admin/Controllers/Api/MenusController.cs @@ -63,8 +63,6 @@ namespace Bootstrap.Admin.Controllers.Api case "user": ret = MenuHelper.RetrieveMenus(User.Identity.Name); break; - default: - break; } return ret; } diff --git a/Bootstrap.Admin/Controllers/Api/RolesController.cs b/Bootstrap.Admin/Controllers/Api/RolesController.cs index 2520c280..ca593aa0 100644 --- a/Bootstrap.Admin/Controllers/Api/RolesController.cs +++ b/Bootstrap.Admin/Controllers/Api/RolesController.cs @@ -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; } diff --git a/Bootstrap.Admin/Controllers/Api/UsersController.cs b/Bootstrap.Admin/Controllers/Api/UsersController.cs index 70c812d0..cee380a1 100644 --- a/Bootstrap.Admin/Controllers/Api/UsersController.cs +++ b/Bootstrap.Admin/Controllers/Api/UsersController.cs @@ -58,21 +58,23 @@ namespace Bootstrap.Admin.Controllers.Api [HttpPost("{id}")] public IEnumerable Post(string id, [FromQuery]string type) { + IEnumerable 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; } /// /// 前台User View调用,新建/更新用户 @@ -114,8 +116,6 @@ namespace Bootstrap.Admin.Controllers.Api case "group": ret = UserHelper.SaveByGroupId(id, userIds); break; - default: - break; } return ret; } diff --git a/Bootstrap.Admin/Models/ProfilesModel.cs b/Bootstrap.Admin/Models/ProfilesModel.cs index d9502896..69b559fd 100644 --- a/Bootstrap.Admin/Models/ProfilesModel.cs +++ b/Bootstrap.Admin/Models/ProfilesModel.cs @@ -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); + } } } }