public async Task <IActionResult> Get(string groupId) { var group = await _groupRepository.GetGroup(groupId); if (group == null) { return(HttpNotFound()); } bool userCanViewGroup = await _securityHelper.CurrentUserCanManageGroup(group.Id); if (!userCanViewGroup) { return(new HttpStatusCodeResult(403)); // Forbidden } Group returnGroup = Map(group); // Fetch the group-specific budget for users in this group foreach (UserSummary user in returnGroup.Users) { UserBudgetState userBudget = await _volatileStorageController.GetUserBudgetState(user.Id, group.Id); user.unitsBudgeted = userBudget.UnitsBudgetted; } return(new ObjectResult(returnGroup) { StatusCode = 200 }); }
public async Task <IActionResult> Get(string groupId) { //TODO: add in group admin/manager authorization check //if (!await CurrentUserCanViewGroup(group)) // return new HttpStatusCodeResult(403); // Forbidden //} // get group details var group = await _groupRepository.GetGroup(groupId); if (group == null) { return(HttpNotFound()); } // build return view List <UserGroupSummary> rtnView = new List <UserGroupSummary>(); foreach (ScampUserGroupMbrship userRef in group.Members) { // get user budget for this group var groupBudget = await _volatileStorageController.GetUserBudgetState(userRef.Id, group.Id); // build summary item for return UserGroupSummary tmpSummary = new UserGroupSummary() { Id = userRef.Id, Name = userRef.Name, isManager = userRef.isManager, // be sure to handle user without a budget values totUnitsUsed = (groupBudget == null ? 0 : groupBudget.UnitsUsed), totUnitsRemaining = (groupBudget == null ? 0 : (groupBudget.UnitsBudgetted - groupBudget.UnitsUsed)) }; rtnView.Add(tmpSummary); // add item to list } // return list return(new ObjectResult(rtnView) { StatusCode = 200 }); }