namespace LaaProduction.Web.Controllers.API.Search { using LaaProduction.Search; using LaaProduction.Web.App_Infrastructure; using LaaProductionDI; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Net; using System.Net.Http; using System.Web.Http; [AuthorizeBearer] [RoutePrefix("api/Search/Wildcard")] public class WildcardController : ApiController { private readonly ISearchManager searchManager; public WildcardController() => this.searchManager = LaaServiceProvider.GetService(); [HttpGet] public IHttpActionResult Get() { var fields = this.searchManager.WildcardFields(); return this.Json(fields); } [HttpPost] public IHttpActionResult Post([FromBody] WildcardSearchModel model) { IEnumerable> results = Array.Empty>(); if (this.ModelState.IsValid) { results = this.searchManager.SearchWildcard(model.Token, model.SelectedFields); } else { return this.ResponseMessage(new HttpResponseMessage { Content = new StringContent(this.ModelState.Content()), RequestMessage = this.Request, StatusCode = HttpStatusCode.BadRequest, Version = this.Request.Version }); } return this.Json(results); } } public class WildcardSearchModel { [Required] [StringLength(50, MinimumLength = 3)] [RegularExpression("^[0-9 a-z-A-Z]+$")] public string Token { get; set; } public string Fields { get; set; } internal IEnumerable SelectedFields { get { if (string.IsNullOrWhiteSpace(this.Fields)) { return Array.Empty(); } return WebUtility .UrlDecode(this.Fields) ?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty(); } } } }