Created
May 3, 2018 15:19
-
-
Save khellang/e38160e5e3e8b3c80748437f7fd77bca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.ComponentModel.DataAnnotations; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.Mvc.ModelBinding; | |
[RequireHttps] | |
[ApiController] | |
[Route("attributes")] | |
public class AttributeController | |
{ | |
[ActionContext] | |
public ActionContext ActionContext { get; set; } | |
[HttpGet("/are/awesome/{id}")] | |
[Produces("application/json"), Consumes("application/json")] | |
[ProducesResponseType(typeof(AttributeModel), StatusCodes.Status200OK)] | |
public IActionResult ICanHasAttributes([FromRoute] Guid id, [FromBody, BindRequired] AttributeModel model) | |
{ | |
if (!ActionContext.ModelState.IsValid) | |
{ | |
return new BadRequestObjectResult(ActionContext.ModelState); | |
} | |
return new OkObjectResult(model); | |
} | |
public class AttributeModel | |
{ | |
[Required] | |
[StringLength(20)] | |
public string Message { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment