This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"values": { | |
"name": "Fred", | |
"favouriteColours": ["red", "green"], | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyApiControllerAttribute : ActionFilterAttribute | |
{ | |
/// <inheritdoc/> | |
public override void OnActionExecuted(ActionExecutedContext ctx) | |
{ | |
if (ctx.Result is ObjectResult objectResult) | |
{ | |
// Create options to match the CMS delivery API, along with any customizations we want for Forms. | |
var options = new JsonSerializerOptions | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyApiControllerAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuted(ActionExecutedContext ctx) | |
{ | |
if (ctx.Result is ObjectResult objectResult) | |
{ | |
var settings = new JsonSerializerSettings | |
{ | |
NullValueHandling = NullValueHandling.Ignore, | |
ContractResolver = new MyApiContractResolver(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FormEntryDtoModelBinder : IModelBinder | |
{ | |
public async Task BindModelAsync(ModelBindingContext bindingContext) | |
{ | |
if (bindingContext == null) | |
{ | |
throw new ArgumentNullException(nameof(bindingContext)); | |
} | |
using (var reader = new StreamReader(bindingContext.HttpContext.Request.Body)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FormEntryDtoModelBinder : IModelBinder | |
{ | |
public async Task BindModelAsync(ModelBindingContext bindingContext) | |
{ | |
if (bindingContext == null) | |
{ | |
throw new ArgumentNullException(nameof(bindingContext)); | |
} | |
using (var reader = new StreamReader(bindingContext.HttpContext.Request.Body)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ActionResult> SubmitEntry( | |
Guid id, | |
[FromBody] [ModelBinder(typeof(FormEntryDtoModelBinder))] FormEntryDto entry) | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ApplyPaging(PackageSearchQuery query, SearchOptions options) | |
{ | |
options.Skip = (query.PageNumber - 1) * query.PageSize; | |
options.Size = query.PageSize; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ApplyOrderBy(SearchOptions options, PackageSearchQuery query) | |
{ | |
switch (query.OrderBy) | |
{ | |
case PackageSearchOrderBy.Alphabetical: | |
options.OrderBy.Add(nameof(PackageModel.Title)); | |
break; | |
case PackageSearchOrderBy.ReverseAlphabetical: | |
options.OrderBy.Add($"{nameof(PackageModel.Title)} desc"); | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ApplyFilter(SearchOptions options, PackageSearchQuery query) | |
{ | |
var filter = new StringBuilder(); | |
bool isFiltered = false; | |
// If category provided, return packages that match on the category Id. | |
if (query.CategoryId.HasValue) | |
{ | |
filter.AppendFormat("{0} eq '{1}'", $"{nameof(PackageModel.Category)}/{nameof(PackageModel.Category.Id)}", query.CategoryId.Value); | |
isFiltered = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void SelectFields(SearchOptions options, PackageSearchQuery query) | |
{ | |
SelectDefaultFields(options); | |
if (!query.Fields.Any()) | |
{ | |
return; | |
} | |
foreach (var field in query.Fields) |