diff --git a/src/Infrastructure/Services/ApplicationClaimsIdentityFactory.cs b/src/Infrastructure/Services/ApplicationClaimsIdentityFactory.cs index 64466bcb..c19aec3c 100644 --- a/src/Infrastructure/Services/ApplicationClaimsIdentityFactory.cs +++ b/src/Infrastructure/Services/ApplicationClaimsIdentityFactory.cs @@ -25,7 +25,7 @@ public ApplicationClaimsIdentityFactory(UserManager userManager _userManager = userManager; _roleManager = roleManager; } - public async override Task CreateAsync(ApplicationUser user) + public override async Task CreateAsync(ApplicationUser user) { var principal = await base.CreateAsync(user); diff --git a/src/Infrastructure/Services/DomainEventService.cs b/src/Infrastructure/Services/DomainEventService.cs index b5b66721..3a722d2b 100644 --- a/src/Infrastructure/Services/DomainEventService.cs +++ b/src/Infrastructure/Services/DomainEventService.cs @@ -1,4 +1,7 @@ -using CleanArchitecture.Razor.Application.Common.Interfaces; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using CleanArchitecture.Razor.Application.Common.Interfaces; using CleanArchitecture.Razor.Application.Common.Models; using CleanArchitecture.Razor.Domain.Common; using MediatR; @@ -31,4 +34,4 @@ private INotification GetNotificationCorrespondingToDomainEvent(DomainEvent doma typeof(DomainEventNotification<>).MakeGenericType(domainEvent.GetType()), domainEvent); } } -} \ No newline at end of file +} diff --git a/src/Infrastructure/Services/UploadService.cs b/src/Infrastructure/Services/UploadService.cs index 65d9fcb2..b9b0cbf7 100644 --- a/src/Infrastructure/Services/UploadService.cs +++ b/src/Infrastructure/Services/UploadService.cs @@ -20,9 +20,8 @@ public async Task UploadAsync(UploadRequest request) var folder = request.UploadType.ToDescriptionString(); var folderName = Path.Combine("Files", folder); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); - bool exists = System.IO.Directory.Exists(pathToSave); - if (!exists) - System.IO.Directory.CreateDirectory(pathToSave); + bool exists = Directory.Exists(pathToSave); + if (!exists) Directory.CreateDirectory(pathToSave); var fileName = request.FileName.Trim('"'); var fullPath = Path.Combine(pathToSave, fileName); var dbPath = Path.Combine(folderName, fileName); @@ -43,7 +42,7 @@ public async Task UploadAsync(UploadRequest request) } } - private static string numberPattern = " ({0})"; + private static string _numberPattern = " ({0})"; public static string NextAvailableFilename(string path) { @@ -53,10 +52,10 @@ public static string NextAvailableFilename(string path) // If path has extension then insert the number pattern just before the extension and return next filename if (Path.HasExtension(path)) - return GetNextFilename(path.Insert(path.LastIndexOf(Path.GetExtension(path)), numberPattern)); + return GetNextFilename(path.Insert(path.LastIndexOf(Path.GetExtension(path)), _numberPattern)); // Otherwise just append the pattern to the path and return next filename - return GetNextFilename(path + numberPattern); + return GetNextFilename(path + _numberPattern); } private static string GetNextFilename(string pattern) diff --git a/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Roles.cshtml.cs b/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Roles.cshtml.cs index 81ef35a8..69889bd5 100644 --- a/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Roles.cshtml.cs +++ b/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Roles.cshtml.cs @@ -111,10 +111,9 @@ public async Task OnPostAsync() } } - catch (Exception ex) + catch (Exception e) { - Response.StatusCode = (int)HttpStatusCode.BadRequest; - return new JsonResult(ex.Message); + return BadRequest(Result.Failure(new string[] { e.Message })); } } public async Task OnGetDataAsync(int page = 1, int rows = 15, string sort = "Name", string order = "asc", string filterRules = "") @@ -128,6 +127,10 @@ public async Task OnGetDataAsync(int page = 1, int rows = 15, str public async Task OnGetDeleteAsync(string id) { var role = await _roleManager.FindByIdAsync(id); + if (role.Name == "Admin") + { + return BadRequest(Result.Failure(new string[] { "Please do not delete the default role." })); + } var result = await _roleManager.DeleteAsync(role); return new JsonResult(result.ToApplicationResult()); } @@ -136,6 +139,10 @@ public async Task OnGetDeleteCheckedAsync([FromQuery] string[] id foreach (var key in id) { var role = await _roleManager.FindByIdAsync(key); + if (role.Name == "Admin") + { + return BadRequest(Result.Failure(new string[] { "Please do not delete the default role." })); + } var result = await _roleManager.DeleteAsync(role); } return new JsonResult(Result.Success()); @@ -189,7 +196,7 @@ public async Task OnPostImportAsync() var iresult = await _roleManager.CreateAsync(role); if (iresult.Succeeded == false) { - return new JsonResult(Result.FailureAsync(iresult.Errors.Select(x => x.Description))); + return BadRequest(Result.FailureAsync(iresult.Errors.Select(x => x.Description))); } } } @@ -198,7 +205,7 @@ public async Task OnPostImportAsync() } catch (Exception e) { - return new JsonResult(Result.Failure(new string[] { e.Message })); + return BadRequest(Result.Failure(new string[] { e.Message })); } } diff --git a/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Users.cshtml b/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Users.cshtml index 47b05f02..fcb36244 100644 --- a/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Users.cshtml +++ b/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Users.cshtml @@ -498,7 +498,7 @@ reload(); }) .catch((error) => { - var msg = error.response.data; + var msg = error.response.data.Errors.join(); bootbox.alert({ size: "small", title: "@_localizer["Error"]", diff --git a/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Users.cshtml.cs b/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Users.cshtml.cs index 7044f519..99583e60 100644 --- a/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Users.cshtml.cs +++ b/src/SmartAdmin.WebUI/Areas/Authorization/Pages/Users.cshtml.cs @@ -122,6 +122,10 @@ public async Task OnGetUnlockAsync(string id) public async Task OnGetDeleteAsync(string id) { var user = await _userManager.FindByIdAsync(id); + if (user.UserName == "administrator") + { + return BadRequest(Result.Failure(new string[] { "Please do not delete the default user." })); + } var result = await _userManager.DeleteAsync(user); return new JsonResult(result.ToApplicationResult()); } @@ -140,6 +144,10 @@ public async Task OnGetDeleteCheckedAsync([FromQuery] string[] id foreach(var key in id) { var user = await _userManager.FindByIdAsync(key); + if (user.UserName == "administrator") + { + return BadRequest(Result.Failure(new string[] { "Please do not delete the default user." })); + } var result = await _userManager.DeleteAsync(user); } return new JsonResult(Result.Success()); @@ -192,7 +200,7 @@ public async Task OnPostImportAsync() if (result.Succeeded) { var importItems = result.Data; - foreach(var item in importItems) + foreach (var item in importItems) { var user = new ApplicationUser { @@ -204,21 +212,22 @@ public async Task OnPostImportAsync() Email = item.Email, PhoneNumber = item.PhoneNumber }; - if((await _userManager.FindByNameAsync(user.UserName)) is null) + if ((await _userManager.FindByNameAsync(user.UserName)) is null) { var iresult = await _userManager.CreateAsync(user, item.Password); if (iresult.Succeeded == false) { - return new JsonResult(Result.FailureAsync(iresult.Errors.Select(x => x.Description))); + return BadRequest(Result.FailureAsync(iresult.Errors.Select(x => x.Description))); } } - + } } return new JsonResult(Result.Success()); - }catch(Exception e) + } + catch (Exception e) { - return new JsonResult(Result.Failure(new string[]{ e.Message})); + return BadRequest(Result.Failure(new string[] { e.Message })); } } diff --git a/src/SmartAdmin.WebUI/Pages/Customers/Index.cshtml b/src/SmartAdmin.WebUI/Pages/Customers/Index.cshtml index fc40fcc0..6c39fbcf 100644 --- a/src/SmartAdmin.WebUI/Pages/Customers/Index.cshtml +++ b/src/SmartAdmin.WebUI/Pages/Customers/Index.cshtml @@ -192,7 +192,7 @@ @await Component.InvokeAsync("ImportExcel", new { importUri = Url.Page("/Customers/Index") + "?handler=Import", getTemplateUri = @Url.Page("/Customers/Index") + "?handler=CreateTemplate", - onImportedSucceeded = "reload()" }) + onImportedSucceeded = "reloadData()" }) @section ScriptsBlock { @@ -205,7 +205,7 @@ @@ -119,7 +119,7 @@