Skip to content

Commit

Permalink
Add constructor to view model
Browse files Browse the repository at this point in the history
  • Loading branch information
cwetanow committed Mar 2, 2017
1 parent 0d0ded3 commit 4f513ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
33 changes: 3 additions & 30 deletions src/Logs.Web/Controllers/LogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,7 @@ public ActionResult List(int count = 1, int page = 1)
{
var logs = this.logService.GetPaged(page, count);
var model = logs
.Select(l => new ShortLogViewModel
{
DateCreated = l.DateCreated,
Entries = l.Entries.Count,
LastActivity = l.LastEntry,
Name = l.Name,
LastActivityUser = l.LastActivityUser,
LogId = l.LogId,
Username = l.User.Name
})
.Select(l => new ShortLogViewModel(l))
.ToPagedList(page, count);

return this.View("List", model);
Expand All @@ -76,16 +67,7 @@ public ActionResult TopLogs(int count = 3)
{
var logs = this.logService.GetTopLogs(count);
var model = logs
.Select(l => new ShortLogViewModel
{
DateCreated = l.DateCreated,
Entries = l.Entries.Count,
LastActivity = l.LastEntry,
Name = l.Name,
LastActivityUser = l.LastActivityUser,
LogId = l.LogId,
Username = l.User.Name
});
.Select(l => new ShortLogViewModel(l));

return this.PartialView("_LogListPartial", model);
}
Expand All @@ -94,16 +76,7 @@ public ActionResult Latest(int count = 3)
{
var logs = this.logService.GetLatestLogs(count);
var model = logs
.Select(l => new ShortLogViewModel
{
DateCreated = l.DateCreated,
Entries = l.Entries.Count,
LastActivity = l.LastEntry,
Name = l.Name,
LastActivityUser = l.LastActivityUser,
LogId = l.LogId,
Username = l.User.Name
});
.Select(l => new ShortLogViewModel(l));

return this.PartialView("_LogListPartial", model);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Logs.Web/Models/Logs/ShortLogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
using System;
using Logs.Models;

namespace Logs.Web.Models.Logs
{
public class ShortLogViewModel
{
public ShortLogViewModel(TrainingLog log)
{
this.DateCreated = log.DateCreated;
this.Entries = log.Entries.Count;
this.LastActivity = log.LastEntry;
this.Name = log.Name;
this.LastActivityUser = log.LastActivityUser;
this.LogId = log.LogId;
this.Username = log.User.Name;
}

public string Name { get; set; }

public int LogId { get; set; }
Expand Down

0 comments on commit 4f513ec

Please sign in to comment.