diff --git a/Lombiq.VueJs.Samples/Controllers/QrCardController.cs b/Lombiq.VueJs.Samples/Controllers/QrCardController.cs index 910f519..6904f7f 100644 --- a/Lombiq.VueJs.Samples/Controllers/QrCardController.cs +++ b/Lombiq.VueJs.Samples/Controllers/QrCardController.cs @@ -34,8 +34,12 @@ public ActionResult Index() }); } - public async Task GetBusinessCard(string cardId) => - await _contentManager.GetAsync(cardId) is { } businessCard + public async Task GetBusinessCard(string cardId) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + return await _contentManager.GetAsync(cardId) is { } businessCard ? Ok(businessCard) : NotFound(); + } } diff --git a/Lombiq.VueJs.Samples/Controllers/VueSfcController.cs b/Lombiq.VueJs.Samples/Controllers/VueSfcController.cs index adaf67c..f5214bf 100644 --- a/Lombiq.VueJs.Samples/Controllers/VueSfcController.cs +++ b/Lombiq.VueJs.Samples/Controllers/VueSfcController.cs @@ -35,15 +35,18 @@ public VueSfcController(IClock clock, IStringLocalizer stringL // Here we show off a way of doing progressive enhancement. This first action has everything you need to access the // page without JS. // Open this from under /Lombiq.VueJs.Samples/VueSfc/EnhancedList - public ActionResult EnhancedList(int page = 1) => View(new EnhancedListViewModel - { - Page = page, - Data = GetDataForPage(page), - }); + public ActionResult EnhancedList(int page = 1) => + ModelState.IsValid + ? View(new EnhancedListViewModel + { + Page = page, + Data = GetDataForPage(page), + }) + : BadRequest(ModelState); // This method returns JSON, providing an API equivalent for the EnhancedList action. The enhanced app will use that // to update results asynchronously. Both use the same source of data. - public ActionResult GetList(int page = 1) => Json(GetDataForPage(page)); + public ActionResult GetList(int page = 1) => ModelState.IsValid ? Json(GetDataForPage(page)) : BadRequest(ModelState); // What is in this method isn't really important, just some sample data to show change. [SuppressMessage("Security", "CA5394:Do not use insecure randomness", Justification = "It's not security critical.")] diff --git a/Lombiq.VueJs/Services/IVueSingleFileComponentShapeAmender.cs b/Lombiq.VueJs/Services/IVueSingleFileComponentShapeAmender.cs index 5a8b6c3..bee4a7a 100644 --- a/Lombiq.VueJs/Services/IVueSingleFileComponentShapeAmender.cs +++ b/Lombiq.VueJs/Services/IVueSingleFileComponentShapeAmender.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Html; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; namespace Lombiq.VueJs.Services; @@ -14,11 +13,11 @@ public interface IVueSingleFileComponentShapeAmender /// Lets you prepend content to the Vue.js template outputted by the shape. The is /// provided to help limit the scope, but you can also ignore it to amend every Vue.js shape. /// - ValueTask> PrependAsync(string shapeName) => new(Enumerable.Empty()); + ValueTask> PrependAsync(string shapeName) => new([]); /// /// Lets you append content to the Vue.js template outputted by the shape. The is /// provided to help limit the scope, but you can also ignore it to amend every Vue.js shape. /// - ValueTask> AppendAsync(string shapeName) => new(Enumerable.Empty()); + ValueTask> AppendAsync(string shapeName) => new([]); } diff --git a/Lombiq.VueJs/Services/ServerSideValuesVueSingleFileComponentShapeAmenderBase.cs b/Lombiq.VueJs/Services/ServerSideValuesVueSingleFileComponentShapeAmenderBase.cs index 18403a3..8d4fbdb 100644 --- a/Lombiq.VueJs/Services/ServerSideValuesVueSingleFileComponentShapeAmenderBase.cs +++ b/Lombiq.VueJs/Services/ServerSideValuesVueSingleFileComponentShapeAmenderBase.cs @@ -2,7 +2,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; namespace Lombiq.VueJs.Services; @@ -38,7 +37,7 @@ public abstract class ServerSideValuesVueSingleFileComponentShapeAmenderBase : I /// public async ValueTask> PrependAsync(string shapeName) { - if (ShapeName != null && ShapeName != shapeName) return Enumerable.Empty(); + if (ShapeName != null && ShapeName != shapeName) return []; var values = await GetPropertyValueAsync(shapeName); var json = JsonConvert.SerializeObject( @@ -46,14 +45,14 @@ public async ValueTask> PrependAsync(string shapeName) Formatting.None, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - return new[] - { + return + [ new HtmlString( ""), - }; + ]; } /// diff --git a/Lombiq.VueJs/Services/VueComponentContentSecurityPolicyProvider.cs b/Lombiq.VueJs/Services/VueComponentContentSecurityPolicyProvider.cs index 2e850cb..95c6d83 100644 --- a/Lombiq.VueJs/Services/VueComponentContentSecurityPolicyProvider.cs +++ b/Lombiq.VueJs/Services/VueComponentContentSecurityPolicyProvider.cs @@ -24,7 +24,7 @@ public ValueTask UpdateAsync(IDictionary securityPolicies, HttpC { if (_state.Active) { - ContentSecurityPolicyProvider.MergeDirectiveValues(securityPolicies, new[] { ScriptSrc }, UnsafeEval); + ContentSecurityPolicyProvider.MergeDirectiveValues(securityPolicies, [ScriptSrc], UnsafeEval); } return ValueTask.CompletedTask; diff --git a/Lombiq.VueJs/Services/VueSingleFileComponentShapeTemplateViewEngine.cs b/Lombiq.VueJs/Services/VueSingleFileComponentShapeTemplateViewEngine.cs index 90fc690..a1ab6e8 100644 --- a/Lombiq.VueJs/Services/VueSingleFileComponentShapeTemplateViewEngine.cs +++ b/Lombiq.VueJs/Services/VueSingleFileComponentShapeTemplateViewEngine.cs @@ -27,7 +27,7 @@ public class VueSingleFileComponentShapeTemplateViewEngine : IShapeTemplateViewE private readonly IEnumerable _amenders; private readonly IEnumerable _converters; - public IEnumerable TemplateFileExtensions { get; } = new[] { ".vue" }; + public IEnumerable TemplateFileExtensions { get; } = [".vue"]; public VueSingleFileComponentShapeTemplateViewEngine( IShapeTemplateFileProviderAccessor fileProviderAccessor, diff --git a/Lombiq.VueJs/Services/VueSingleFileComponentTemplateHarvester.cs b/Lombiq.VueJs/Services/VueSingleFileComponentTemplateHarvester.cs index 0c4c927..0218b59 100644 --- a/Lombiq.VueJs/Services/VueSingleFileComponentTemplateHarvester.cs +++ b/Lombiq.VueJs/Services/VueSingleFileComponentTemplateHarvester.cs @@ -2,7 +2,6 @@ using OrchardCore.Mvc.Utilities; using System; using System.Collections.Generic; -using System.Linq; namespace Lombiq.VueJs.Services; @@ -10,16 +9,16 @@ public class VueSingleFileComponentTemplateHarvester : IShapeTemplateHarvester { private const string SubPath = "Assets/Scripts/VueComponents"; - public IEnumerable SubPaths() => new[] { SubPath }; + public IEnumerable SubPaths() => [SubPath]; public IEnumerable HarvestShape(HarvestShapeInfo info) => !info.SubPath.StartsWith(SubPath, StringComparison.OrdinalIgnoreCase) - ? Enumerable.Empty() - : new[] - { + ? [] + : + [ new HarvestShapeHit { ShapeType = "VueComponent-" + info.FileName.ToPascalCaseDash(), }, - }; + ]; }