Skip to content

Instantly share code, notes, and snippets.

@khellang
Created May 3, 2018 15:19
Show Gist options
  • Save khellang/e38160e5e3e8b3c80748437f7fd77bca to your computer and use it in GitHub Desktop.
Save khellang/e38160e5e3e8b3c80748437f7fd77bca to your computer and use it in GitHub Desktop.
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