Last active
September 13, 2015 15:30
-
-
Save jmarmolejos/3b4fc55f7a6b1c5fedac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function (doc) { | |
emit(doc._id, doc); | |
} |
This file contains hidden or 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 async Task<List<Notification>> Get() | |
{ | |
var uriBuilder = GetCouchUrl(); | |
using (var client = new MyCouchClient(uriBuilder.Build())) | |
{ | |
var notifications = await client.Views.QueryAsync<Notification>(new QueryViewRequest("notifications-doc", "all-notifications")); | |
return notifications.Rows.Select(r => r.Value).ToList(); | |
} | |
} |
This file contains hidden or 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
private MyCouchUriBuilder GetCouchUrl() | |
{ | |
// assuming you're using cloudant | |
return new MyCouchUriBuilder("https://[username].cloudant.com/") | |
.SetDbName("notifications") | |
.SetBasicCredentials("[usename]", "[password]"); | |
} |
This file contains hidden or 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
namespace CouchWebApi.Models | |
{ | |
public class Notification | |
{ | |
public string Alert { get; set; } | |
public int Count { get; set; } | |
} | |
} |
This file contains hidden or 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 async Task<Notification> Post(Notification notification) | |
{ | |
var uriBuilder = GetCouchUrl(); | |
using (var client = new MyCouchClient(uriBuilder.Build())) | |
{ | |
var response = await client.Entities.PostAsync(notification); | |
return response.Content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment