Created
June 19, 2013 11:33
-
-
Save NathanGloyn/5813611 to your computer and use it in GitHub Desktop.
Sample Web Api controller which uses actions against a resource using same verb. How could this be done in a verb only form?
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
using System.Net; | |
using System.Net.Http; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Http; | |
using Sample.Repository | |
namespace Sample.Controllers | |
{ | |
[Authorize] | |
public class QueueController : ApiController | |
{ | |
private readonly IRepository _repository; | |
public QueueController(IRamsRepository repository) | |
{ | |
_repository = repository; | |
} | |
public QueueDisplay Get() | |
{ | |
return _repository.CurrentQueue(); | |
} | |
[HttpPut] | |
public HttpResponseMessage CancelItem(Guid id) | |
{ | |
_repository.Cancel(id); | |
return new HttpResponseMessage(HttpStatusCode.OK); | |
} | |
[HttpPut] | |
public HttpResponseMessage RequeueItem(Guid id) | |
{ | |
_repository.Requeue(id); | |
return new HttpResponseMessage(HttpStatusCode.OK); | |
} | |
[HttpPut] | |
public HttpResponseMessage SaveItem(QueueItem model) | |
{ | |
if (!ModelState.IsValid) | |
{ | |
return new HttpResponseMessage(HttpStatusCode.BadRequest); | |
} | |
_repository.Save(model); | |
return new HttpResponseMessage(HttpStatusCode.OK); | |
} | |
[HttpPut] | |
public HttpResponseMessage CommitItem(Guid id) | |
{ | |
_repository.Commit(id); | |
return new HttpResponseMessage(HttpStatusCode.OK); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment