Skip to content

Instantly share code, notes, and snippets.

@hartez
Created June 23, 2014 18:07
Show Gist options
  • Save hartez/2c012a202a2f38ba5cb8 to your computer and use it in GitHub Desktop.
Save hartez/2c012a202a2f38ba5cb8 to your computer and use it in GitHub Desktop.
Controller without documentation
public class AddressController : ApiController
{
public IEnumerable<AddressViewModel> Get()
{
return Addresses.Get();
}
[Route(Name = "GetAddress")]
public AddressViewModel Get(int id)
{
return Addresses.Get(id);
}
// POST api/address
[ResponseType(typeof(AddressViewModel))]
public IHttpActionResult Post(AddressInputModel address)
{
if(ModelState.IsValid)
{
var id = Addresses.Add(address);
var uri = new Uri(Url.Link("GetAddress", new { id }));
return Created(uri, Addresses.Get(id));
}
return BadRequest(ModelState);
}
public void Put(int id, AddressInputModel address)
{
Addresses.Update(id, address);
}
public void Delete(int id)
{
Addresses.Remove(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment