1
1
using CheckDrive . Web . Stores . Accounts ;
2
2
using CheckDrive . Web . Stores . Dashbord ;
3
- using CheckDrive . Web . ViewModels ;
3
+ using CheckDrive . Web . Stores . Debts ;
4
+ using CheckDrive . Web . Stores . MockDashboard ;
5
+ using CheckDrive . Web . Stores . SplineCharts ;
6
+ using CheckDrive . Web . ViewModels . Dashboard ;
4
7
using Microsoft . AspNetCore . Mvc ;
5
- using NuGet . Common ;
6
8
using System . IdentityModel . Tokens . Jwt ;
7
9
using System . Security . Claims ;
8
10
@@ -12,47 +14,68 @@ public class DashboardController : Controller
12
14
{
13
15
private readonly IDashboardStore _store ;
14
16
private readonly IAccountDataStore _accountDataStore ;
15
- public DashboardController ( IDashboardStore store , IAccountDataStore accountDataStore )
17
+ private readonly IMockDashboardStore _mockDashboardStore ;
18
+ private readonly ICheckPointStore _checkPointStore ;
19
+ public DashboardController ( IDashboardStore store ,
20
+ IAccountDataStore accountDataStore ,
21
+ IMockDashboardStore mockDashboardStore ,
22
+ ICheckPointStore checkPointStore )
16
23
{
17
24
_store = store ;
18
25
_accountDataStore = accountDataStore ;
26
+ _mockDashboardStore = mockDashboardStore ;
27
+ _checkPointStore = checkPointStore ;
19
28
}
20
29
21
30
public async Task < IActionResult > Index ( )
22
31
{
23
32
string token = HttpContext . Request . Cookies [ "tasty-cookies" ] ;
33
+
24
34
var tokenHandler = new JwtSecurityTokenHandler ( ) ;
25
35
var jwtToken = tokenHandler . ReadToken ( token ) as JwtSecurityToken ;
36
+
26
37
if ( jwtToken == null )
27
38
{
28
39
return RedirectToAction ( "Login" , "Account" ) ;
29
40
}
41
+
30
42
var accountId = jwtToken . Claims . First ( claim => claim . Type == ClaimTypes . NameIdentifier ) . Value ;
31
43
int accountIds = Int32 . Parse ( accountId ) ;
32
44
33
45
TempData [ "UserName" ] = _accountDataStore . GetAccountAsync ( accountIds )
34
46
. Result . FirstName ;
35
47
TempData . Keep ( "UserName" ) ;
48
+
36
49
var dashboard = await _store . GetDashboard ( ) ;
50
+ var mockDashboard = await _mockDashboardStore . GetDashboard ( ) ;
51
+ var checkPoints = _checkPointStore . GetAll ( "" ) ;
52
+
53
+
54
+ dashboard . CheckPoints = checkPoints ;
55
+ dashboard . OilAmount = mockDashboard . OilAmount ;
37
56
38
57
if ( dashboard is null )
39
58
{
40
59
return BadRequest ( ) ;
41
60
}
61
+
42
62
SetViewBagProperties ( dashboard ) ;
43
63
44
64
return View ( ) ;
45
65
}
66
+
46
67
private void SetViewBagProperties ( DashboardViewModel dashboard )
47
68
{
48
69
var summary = dashboard . Summary ;
49
-
70
+
50
71
ViewBag . MonthlyFuelConsumption = summary . MonthlyFuelConsumption . ToString ( "0.00" ) ;
51
72
ViewBag . CarsCount = summary . CarsCount ;
52
73
ViewBag . DriversCount = summary . DriversCount ;
53
74
54
75
ViewBag . EmployeesCountByRole = dashboard . EmployeesCountByRoles ;
55
76
ViewBag . SplineChartData = dashboard . SplineCharts ;
77
+ ViewBag . OilAmount = dashboard . OilAmount ;
78
+ ViewBag . CheckPoint = dashboard . CheckPoints ;
56
79
}
57
80
}
58
81
}
0 commit comments