public async Task <IActionResult> Index(int?month, int?year) { var userName = User.FindFirstValue(ClaimTypes.Name); // will give the user's userName var userBillService = new UserBillService(); var usViewModel = new UserBillsViewModel(); var userService = new UserService(); var userId = await userService.GetUserId(userName); var navHelper = UserBillService.GetNavigationHelper(month, year); ViewBag.PreviousMonth = navHelper.PrevMonth; ViewBag.PreviousMonthName = new DateTime(navHelper.CurrentYear, navHelper.PrevMonth, 1).ToString(Format, CultureInfo.InvariantCulture); ViewBag.PreviousMonthsYear = navHelper.PrevMonthsYear; ViewBag.MonthName = new DateTime(navHelper.CurrentYear, navHelper.CurrentMonth, 1).ToString(Format, CultureInfo.InvariantCulture); ViewBag.NextMonth = navHelper.NextMonth; ViewBag.NextMonthName = new DateTime(navHelper.CurrentYear, navHelper.NextMonth, 1).ToString(Format, CultureInfo.InvariantCulture); ViewBag.NextMonthsYear = navHelper.NextMonthsYear; var userBills = userBillService.GetMonthlyBillSetByUserIdAndMonthYear(userId, navHelper.CurrentMonth, navHelper.CurrentYear); var userDetails = await userService.GetUserDetailByUserId(userId); ViewData["UsersFirstName"] = userDetails.FirstName; usViewModel.UserDetails = userDetails; usViewModel.UserMonthlyBillSet = userBills; return(View(usViewModel)); }
// GET: Bills public async Task <IActionResult> Index() { var userName = User.FindFirstValue(ClaimTypes.Name); var userService = new UserService(); var userId = await userService.GetUserId(userName); var userDetails = await userService.GetUserDetailByUserId(userId); var userBillService = new UserBillService(); var ubViewModel = new UserBillsViewModel { UserDetails = userDetails, UserBillSet = userBillService.GetBillsByUserIdConsolidated(userId) }; ViewData["UsersFirstName"] = userDetails.FirstName; return(View(ubViewModel)); }
public async Task <IActionResult> UserBills(string id) { var user = await userManager.FindByIdAsync(id); if (user == null) { ViewBag.ErrorMessage = $"The user with Id = {id} cannot be found"; return(View("NotFound")); } var bills = await _context.Bill.Where(b => b.CustomerId.Contains(id)).ToListAsync(); var model = new UserBillsViewModel { Id = user.Id, Email = user.Email, PremisesNumber = user.PremisesNumber, Bills = bills }; return(View(model)); }