-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeController.cs
More file actions
61 lines (56 loc) · 1.88 KB
/
HomeController.cs
File metadata and controls
61 lines (56 loc) · 1.88 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MVCFinApp.Data;
using MVCFinApp.Models;
using MVCFinApp.Models.ViewModels;
namespace MVCFinApp.Controllers
{
[Authorize]
public class HomeController : Controller
{
private readonly ApplicationDbContext _context;
private readonly ILogger<HomeController> _logger;
private readonly UserManager<FAUser> _userManager;
public HomeController(ApplicationDbContext context, ILogger<HomeController> logger, UserManager<FAUser> userManager)
{
_context = context;
_logger = logger;
_userManager = userManager;
}
public async Task<IActionResult> Index()
{
var user = await _userManager.GetUserAsync(User);
string houseHoldName = null;
if (user.HouseHoldId != null)
{
houseHoldName = _context.HouseHold.FirstOrDefault(u => u.Id == user.HouseHoldId).Name;
}
var model = new LobbyVM
{
Role = (await _userManager.GetRolesAsync(user))[0],
HouseHold = houseHoldName
};
if (user.HouseHoldId != null)
{
return RedirectToAction("Dashboard", "HouseHolds");
}
return View(model);
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}