diff --git a/sample-app/NoteTaker/NoteTaker/Controllers/NoteController.cs b/sample-app/NoteTaker/NoteTaker/Controllers/NoteController.cs index bed1947..c01e98a 100755 --- a/sample-app/NoteTaker/NoteTaker/Controllers/NoteController.cs +++ b/sample-app/NoteTaker/NoteTaker/Controllers/NoteController.cs @@ -16,12 +16,48 @@ public class NoteController : Controller public ActionResult Index() { - var json = Couch.Uri.Get("_all_docs?include_docs=true"); - var notes = JsonConvert.DeserializeObject>(json); - - return View(notes.Items.Select(i=>i.Item)); + var notes = GetNotes(); + var tags = GetTags(); + + return View(new NoteList() + { + Notes=notes.Items.Select(n=>n.Document), + Tags=tags.Items.ToDictionary(x=>x.Key,x=>Int32.Parse(x.Value)) + }); + } + + public ActionResult Tagged(string id) + { + var notes = GetNotesByTag(id); + var tags = GetTags(); + + return View("Index",new NoteList() + { + Notes = notes.Items.Select(n => n.Document), + Tags = tags.Items.ToDictionary(x => x.Key, x => Int32.Parse(x.Value)) + }); } + public DocumentCollection GetNotes() + { + var json = Couch.Uri.Get("_design/Notes/_view/all?include_docs=true"); + return JsonConvert.DeserializeObject>(json); + } + + public DocumentCollection GetNotesByTag(string tag) + { + var json = Couch.Uri.Get("_design/Tags/_view/all?key=\""+tag+"\"&reduce=false&include_docs=true"); + return JsonConvert.DeserializeObject>(json); + } + + public DocumentCollection GetTags() + { + var json = Couch.Uri.Get("_design/Tags/_view/all?group_level=1"); + return JsonConvert.DeserializeObject>(json); + } + + + public ActionResult Create() { diff --git a/sample-app/NoteTaker/NoteTaker/Models/Note.cs b/sample-app/NoteTaker/NoteTaker/Models/Note.cs index 7d377c1..75e5bae 100755 --- a/sample-app/NoteTaker/NoteTaker/Models/Note.cs +++ b/sample-app/NoteTaker/NoteTaker/Models/Note.cs @@ -16,6 +16,6 @@ public class Note public string Title { get; set; } public string Text { get; set; } - + public string Tags { get; set; } } } \ No newline at end of file diff --git a/sample-app/NoteTaker/NoteTaker/Views/Note/Edit.cshtml b/sample-app/NoteTaker/NoteTaker/Views/Note/Edit.cshtml index fbb1208..b2d2990 100755 --- a/sample-app/NoteTaker/NoteTaker/Views/Note/Edit.cshtml +++ b/sample-app/NoteTaker/NoteTaker/Views/Note/Edit.cshtml @@ -36,6 +36,14 @@ @Html.TextAreaFor(model => model.Text) +
+ @Html.LabelFor(model => model.Tags) +
+
+ @Html.EditorFor(model => model.Tags) + (separated by spaces) +
+

diff --git a/sample-app/NoteTaker/NoteTaker/Views/Note/Index.cshtml b/sample-app/NoteTaker/NoteTaker/Views/Note/Index.cshtml index f4627d3..0b96897 100755 --- a/sample-app/NoteTaker/NoteTaker/Views/Note/Index.cshtml +++ b/sample-app/NoteTaker/NoteTaker/Views/Note/Index.cshtml @@ -1,4 +1,4 @@ -@model IEnumerable +@model NoteTaker.Models.NoteList @{ ViewBag.Title = "List"; @@ -14,21 +14,33 @@ - -@foreach (var item in Model) { +@if (!Model.Notes.Any()){ + + + No Notes to show. + + +} +@foreach (var item in Model.Notes) +{ @Html.DisplayFor(modelItem => item.Title) - @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | - @Html.ActionLink("Delete", "Delete", new { id=item.Id,rev=item.Revision }) + @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | + @Html.ActionLink("Delete", "Delete", new { id = item.Id, rev = item.Revision }) } - +

@Html.ActionLink("Create New", "Create")