Created
January 21, 2013 19:13
-
-
Save OndeVai/4588459 to your computer and use it in GitHub Desktop.
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 MatchesController : ApiController | |
{ | |
private static IMatchRepository _repository; | |
public MatchesController(IMatchRepository repository) | |
{ | |
_repository = repository; | |
} | |
public async Task<HttpResponseMessage> Get() | |
{ | |
var items = await _repository.GetAsync(); | |
var testDate = new DateTime(2010, 03, 01); | |
//todo this would be an actionfilter or message inspector?? | |
//i would query items on the if modified and if nothing returned, i would send back the 204 | |
if (Request.Headers.Contains("If-Modified-Since")) | |
{ | |
var checkDateHeaders = Request.Headers.GetValues("If-Modified-Since"); | |
var date = DateTime.Parse(checkDateHeaders.FirstOrDefault()); | |
if (date <= testDate) | |
{ | |
return Request.CreateResponse(HttpStatusCode.NoContent); | |
} | |
} | |
/** | |
//jquery sample handling the 204... | |
$.ajax( | |
'http://localhost/api/matches', | |
{ | |
ifModified: true, | |
dataType: 'json' | |
} | |
).done( | |
function(data, statusDesc, jqXHR) { | |
if (jqXHR.status === 204) { | |
alert('nothing changed'); | |
return; | |
} | |
$('#test').empty(); | |
for (var i = 0; i < data.length; i++) { | |
$('#test').append('<li><h2>' + data[i].Name + '</h2><img src="' + data[i].Original + '"/> <img src="data:image/jpeg;base64,' + data[i].Thumbnail + '" alt="Yours pic" class="pic2" /></li>'); | |
} | |
}); | |
**/ | |
var response = Request.CreateResponse(HttpStatusCode.OK, items); | |
response.Content.Headers.LastModified = testDate; | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment