private async Task <IActionResult> DoPost(string configuration) { // read test case from request body var models = await Request.ReadAsAsync <RhinoPageModel[]>().ConfigureAwait(false); // exit conditions if (models.Length == 0) { return(await this .ErrorResultAsync("At least one model must be provided.", HttpStatusCode.BadRequest) .ConfigureAwait(false)); } if (!models.SelectMany(i => i.Entries).Any()) { return(await this .ErrorResultAsync("At least one model entry must be provided.", HttpStatusCode.BadRequest) .ConfigureAwait(false)); } // setup var collection = new RhinoPageModelCollection(); collection.Configurations ??= new List <string>(); collection.Models = models; if (!string.IsNullOrEmpty(configuration)) { collection.Configurations.Add(configuration); } // get credentials var credentials = Request.GetAuthentication(); // response var responseBody = new { Data = new { Id = repository.Post(credentials, collection) } }; // exit conditions if (string.IsNullOrEmpty(responseBody.Data.Id)) { return(await this .ErrorResultAsync("All the provided Models Collections already exists. Please provide a unique Collection or clean old ones.") .ConfigureAwait(false)); } // results return(this.ContentResult(responseBody, HttpStatusCode.Created)); }
// TODO: clean private async Task <IActionResult> DoPost(string configuration) { // read test case from request body var models = await Request.ReadAsAsync <RhinoPageModel[]>().ConfigureAwait(false); // exit conditions if (models.Length == 0) { return(GetErrorResults(message: "At least one model must be provided.")); } if (!models.SelectMany(i => i.Entries).Any()) { return(GetErrorResults(message: "At least one model entry must be provided.")); } // setup var collection = new RhinoPageModelCollection(); collection.Configurations ??= new List <string>(); collection.Models = models; if (!string.IsNullOrEmpty(configuration)) { collection.Configurations.Add(configuration); } // get credentials var credentials = Request.GetAuthentication(); // response var data = new { Data = new { Id = repository.Post(credentials, collection) } }; // exit conditions if (string.IsNullOrEmpty(data.Data.Id)) { return(GetErrorResults( message: "All the provided Models Collections already exists. Please provide a unique Collection.")); } // results return(new ContentResult { Content = JsonConvert.SerializeObject(data, jsonSettings), ContentType = MediaTypeNames.Application.Json, StatusCode = HttpStatusCode.Created.ToInt32() }); }