Skip to content

Instantly share code, notes, and snippets.

@Quit
Created September 4, 2015 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quit/c236ad7b1646828b8469 to your computer and use it in GitHub Desktop.
Save Quit/c236ad7b1646828b8469 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Web.Http;
namespace SelfHost.WebApi.v1
{
[RoutePrefix("api/v1/population/")]
public class PopulationController : ApiController
{
// For the sake of this test, IPopulationApi would be the api to
// control populations, like animals or plants.
private IPopulationApi _api;
// Dependency Injection, performed by web API
public PopulationController(IPopulationApi api)
{
this._api = api;
}
/// <summary>
/// Returns all animals and plants.
/// </summary>
// GET api/v1/population/members
[Route("members")]
public IEnumerable<IMember> GetMembers()
{
return _api.GetMembers();
}
/// <summary>
/// Returns all animals or plants of species <paramref name="speciesName"/>
/// </summary>
// GET api/v1/population/members/animalDeer
[Route("members/{speciesName}")]
public IEnumerable<IMember> GetMembers(string speciesName)
{
return _api.GetMembers(speciesName);
}
/// <summary>
/// Wipes out an entire species.
/// </summary>
// DELETE api/v1/population/erase/animalDeer
[Route("erase/{speciesName}")]
[HttpDelete]
[Authorize(Roles = "Administrator")]
public void EraseSpecies(string speciesName)
{
_api.EraseSpecies(speciesName);
}
/// <summary>
/// Adds <paramref name="member"/> to the species <paramref name="speciesName"/>
/// </summary>
// POST api/v1/
[Route("add/{speciesName}")]
[HttpPost]
[Authorize(Roles = "Administrator")]
public void AddMember(string speciesName, IMember member)
{
_api.AddMember(speciesName, member);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment