Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Work on #26
Browse files Browse the repository at this point in the history
  • Loading branch information
cdemi committed Oct 15, 2018
1 parent 8045151 commit 594fac8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
2 changes: 2 additions & 0 deletions NewsletterCurator.Data/Category.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

Expand All @@ -10,5 +11,6 @@ public class Category
public Guid ID { get; set; }
[Required]
public string Name { get; set; }
public List<Newsitem> Newsitems { get; set; }
}
}
9 changes: 7 additions & 2 deletions NewsletterCurator.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using NewsletterCurator.Data;
using NewsletterCurator.Web.Models;

namespace NewsletterCurator.Web.Controllers
{
Expand All @@ -13,9 +16,11 @@ public HomeController(NewsletterCuratorContext newsletterCuratorContext)
this.newsletterCuratorContext = newsletterCuratorContext;
}

public IActionResult Index()
public async Task<IActionResult> Index()
{
return View(newsletterCuratorContext.Categories.ToList());
var categoryNewsItemsViewModels = await newsletterCuratorContext.Newsitems.Where(n => n.IsAlreadySent == false).GroupBy(n => n.Category).Select(c => new CategoryNewsItemsViewModel { Category = c.Key, Newsitems = c.ToList() }).ToListAsync();

return View(categoryNewsItemsViewModels);
}
}
}
12 changes: 12 additions & 0 deletions NewsletterCurator.Web/Models/CategoryNewsItemsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using NewsletterCurator.Data;

namespace NewsletterCurator.Web.Models
{
public class CategoryNewsItemsViewModel
{
public Category Category { get; set; }

public List<Newsitem> Newsitems { get; set; }
}
}
37 changes: 29 additions & 8 deletions NewsletterCurator.Web/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
@model List<Category>
@model List<CategoryNewsItemsViewModel>

<div class="container">
<h1>Newsletter Curator</h1>
<ul>
@foreach (var category in Model)
{
<li>@category.ID - @category.Name</li>
}
</ul>
@foreach (var categoryNewsItemsViewModel in Model)
{
<h1>@categoryNewsItemsViewModel.Category.Name</h1>
<table class="table-striped table-bordered table-hover">
<thead>
<tr>
<th width="5%" scope="col"></th>
<th width="15%" scope="col">Title</th>
<th width="80%" scope="col">Summary</th>
</tr>
</thead>
<tbody>
@foreach (var newsItem in categoryNewsItemsViewModel.Newsitems)
{
<tr>
<td><input type="checkbox" /></td>
<td>@newsItem.Title</td>
<td>@newsItem.Summary</td>
</tr>
}
</tbody>
</table>
}

<a href="javascript: document.location='@Url.AbsoluteAction("Add", "Newsitem")?url=' + encodeURIComponent(document.location)">Add to Newsletter</a>

<form method="get" asp-action="Add" asp-controller="Newsitem">
<input type="url" name="url" placeholder="URL" />
<input type="submit" value="Submit"/>
</form>
</div>

0 comments on commit 594fac8

Please sign in to comment.