-
Notifications
You must be signed in to change notification settings - Fork 0
/
HopsViewModel.cs
42 lines (38 loc) · 1.63 KB
/
HopsViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Brew.ViewModels.Ingredients
{
public class HopsViewModel
{
public readonly PagedList<HopViewModel> Hops;
public HopsViewModel(uint pageNo)
{
var allHops = new List<HopViewModel>();
using (var context = new Models.ModelsContext())
{
var dbModel = (from r in context.Hops select r);
foreach (var hop in dbModel)
{
allHops.Add(new HopViewModel
{
Type = hop.HopType.ToString(),
//Amount = hop.Amount, // TODO get from join table
Alpha = hop.Alpha,
Beta = (double)hop.Beta,
PercentHumulene = (double)hop.Humulene,
PercentCaryophyllene = (double)hop.Caryophyllene,
PercentCohumulone = (double)hop.Cohumulone,
PercentMyrcene = (double)hop.Myrcene,
UsedDuring = -1,
// UsageTime = TimeSpan.FromMilliseconds(hop.Time), TODO get from join table
Form = hop.HopForm.ToString(),
Stability = (double)hop.HSI
});
}
}
Hops = new PagedList<HopViewModel>(allHops.GetRange((int)(pageNo * 30), (int)Math.Min(allHops.Count, pageNo * 30 + 30)), allHops.Count < 30 ? 0 : (uint)Math.Ceiling(allHops.Count / 30d), pageNo, 30);
}
}
}