Created
June 23, 2014 18:07
-
-
Save hartez/2c012a202a2f38ba5cb8 to your computer and use it in GitHub Desktop.
Controller without documentation
This file contains 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
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