public async Task <IActionResult> HouseholdApplyMinutesRead(HouseholdListViewModel model) { if (model.MinutesRead < 1) { TempData[MinutesReadMessage] = "You must enter how many minutes!"; } else if (!string.IsNullOrWhiteSpace(model.UserSelection)) { List <int> userSelection = model.UserSelection .Split(',') .Where(_ => !string.IsNullOrWhiteSpace(_)) .Select(Int32.Parse) .Distinct() .ToList(); try { await _activityService.LogHouseholdMinutesAsync(userSelection, model.MinutesRead); ShowAlertSuccess("Minutes applied!"); } catch (GraException gex) { TempData[MinutesReadMessage] = gex.Message; } } else { TempData[MinutesReadMessage] = "No household members selected."; } return(RedirectToAction("Household")); }
public async Task <IActionResult> Household() { var authUser = await _userService.GetDetails(GetId(ClaimType.UserId)); var hasAccount = true; var activeUserId = GetActiveUserId(); if (authUser.Id != activeUserId) { User activeUser = await _userService.GetDetails(activeUserId); if (string.IsNullOrWhiteSpace(activeUser.Username)) { hasAccount = false; } } User headUser = null; bool authUserIsHead = !authUser.HouseholdHeadUserId.HasValue; if (!authUserIsHead) { headUser = await _userService.GetDetails((int)authUser.HouseholdHeadUserId); } else { authUser.HasNewMail = await _mailService.UserHasUnreadAsync(authUser.Id); authUser.VendorCode = await _vendorCodeService.GetUserVendorCodeAsync(authUser.Id); } var household = await _userService .GetHouseholdAsync(authUser.HouseholdHeadUserId ?? authUser.Id, authUserIsHead, authUserIsHead, authUserIsHead); HouseholdListViewModel viewModel = new HouseholdListViewModel() { Users = household, HouseholdCount = household.Count(), HasAccount = hasAccount, Head = headUser ?? authUser, AuthUserIsHead = authUserIsHead, ActiveUser = activeUserId }; if (TempData.ContainsKey(MinutesReadMessage)) { viewModel.MinutesReadMessage = (string)TempData[MinutesReadMessage]; } if (TempData.ContainsKey(SecretCodeMessage)) { viewModel.SecretCodeMessage = (string)TempData[SecretCodeMessage]; } return(View(viewModel)); }
public ActionResult List() { HouseholdDaLogic data = new HouseholdDaLogic(new TwnContext(), User.Identity.GetUserId()); HouseholdListViewModel viewModel = new HouseholdListViewModel() { Households = data.GetCollection().ToList() }; return(View("List", viewModel)); }
public async Task <IActionResult> Household(int page = 1) { int take = 15; int skip = take * (page - 1); var authUser = await _userService.GetDetails(GetId(ClaimType.UserId)); User activeUser = await _userService.GetDetails(GetActiveUserId()); User headUser = null; if (authUser.HouseholdHeadUserId != null) { headUser = await _userService.GetDetails((int)authUser.HouseholdHeadUserId); } var household = await _userService .GetPaginatedFamilyListAsync(authUser.HouseholdHeadUserId ?? authUser.Id, skip, take); // authUser is the head of the family bool authUserIsHead = authUser.Id == household.Data.FirstOrDefault()?.HouseholdHeadUserId; PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = household.Count, CurrentPage = page, ItemsPerPage = take }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } HouseholdListViewModel viewModel = new HouseholdListViewModel() { Users = household.Data, PaginateModel = paginateModel, HouseholdCount = household.Count, HasAccount = !string.IsNullOrWhiteSpace(activeUser.Username), Head = headUser ?? authUser, AuthUserIsHead = authUserIsHead, ActiveUser = GetActiveUserId() }; return(View(viewModel)); }
public async Task <IActionResult> HouseholdApplySecretCode(HouseholdListViewModel model) { if (string.IsNullOrWhiteSpace(model.SecretCode)) { TempData[SecretCodeMessage] = "You must enter a code!"; } else if (!string.IsNullOrWhiteSpace(model.UserSelection)) { List <int> userSelection = model.UserSelection .Split(',') .Where(_ => !string.IsNullOrWhiteSpace(_)) .Select(Int32.Parse) .Distinct() .ToList(); try { var codeApplied = await _activityService .LogHouseholdSecretCodeAsync(userSelection, model.SecretCode); if (codeApplied) { ShowAlertSuccess("Secret Code applied!"); } else { TempData[SecretCodeMessage] = "All selected members have already entered that Secret Code."; } } catch (GraException gex) { TempData[SecretCodeMessage] = gex.Message; } } else { TempData[SecretCodeMessage] = "No household members selected."; } return(RedirectToAction("Household")); }
public async Task <IActionResult> Household(int id, int page = 1) { try { int take = 15; int skip = take * (page - 1); var user = await _userService.GetDetails(id); SetPageTitle(user); User headOfHousehold = new User(); if (user.HouseholdHeadUserId.HasValue) { headOfHousehold = await _userService .GetDetails(user.HouseholdHeadUserId.Value); } else { headOfHousehold = user; } var household = await _userService .GetPaginatedFamilyListAsync(headOfHousehold.Id, skip, take); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = household.Count, CurrentPage = page, ItemsPerPage = take }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } HouseholdListViewModel viewModel = new HouseholdListViewModel() { Users = household.Data, PaginateModel = paginateModel, Id = id, HouseholdCount = household.Count, HeadOfHouseholdId = user.HouseholdHeadUserId, HasAccount = !string.IsNullOrWhiteSpace(user.Username), CanEditDetails = UserHasPermission(Permission.EditParticipants), Head = headOfHousehold }; return(View(viewModel)); } catch (GraException gex) { ShowAlertWarning("Unable to view participant's household: ", gex); return(RedirectToAction("Index")); } }