private RewardsViewModel BuildRewardView(int id) { string current_user = User.Identity.Name; var testchild = BL.GetChildAndRewardsForId(id); var model = new RewardsViewModel(); var rewardsAwarded = BL.GetRewardAwardedForId(id).OrderByDescending(a => a.RewardReceivedDate).ToList(); List <RewardAwardedVM> rewardsAwardedVM = BuildRewardsAwardedVM(rewardsAwarded); model.RewardsAwardedVM = rewardsAwardedVM; var goals = BL.GetGoals().Where(a => a.ParentUser == current_user).ToList(); var vmlist = new List <ChildRewardVM>(); foreach (var x in goals) { var rewardallocated = testchild.ChildRewards.Where(a => a.GoalId == x.GoalId).FirstOrDefault(); int pointsallocated = 0; var cr = new ChildRewardVM(); if (rewardallocated != null) { cr.RewardComplete = rewardallocated.RewardComplete; cr.WantReward = rewardallocated.RewardRequested; cr.GiveReward = rewardallocated.RewardComplete; pointsallocated = rewardallocated.PointsAllocated; } cr.ChildId = id; cr.Administrator = true; // temporary as will do another way cr.GoalCompletePoints = x.GoalPointsRequired; cr.GoalName = x.GoalName; cr.GoalId = x.GoalId; cr.GoalPoints = pointsallocated; // fetch from rewards cr.GoalPointsOriginal = pointsallocated; // fetch from rewards if (pointsallocated == x.GoalPointsRequired) { cr.SliderVisible = false; } else { cr.SliderVisible = true; } vmlist.Add(cr); } model.ChildRewardsVM = vmlist; ViewBag.Child = BL.GetChildForId(id); ViewBag.Administrator = true; model.Administrator = true; model.UserLevel = false; model.Child = BL.GetChildForId(id); return(model); }
public ActionResult Reward(int id = 1) { string current_user = User.Identity.Name; // note, might need to change when not a logged in User // var testreward = BL.GetChildRewardForId(1, 2); var testchild = BL.GetChildAndRewardsForId(id); var model = new RewardsViewModel(); model.ShowAllocation = true; model.ShowRewards = false; var rewardsAwarded = BL.GetRewardAwardedForId(id); List <RewardAwardedVM> rewardsAwardedVM = BuildRewardsAwardedVM(rewardsAwarded); model.RewardsAwardedVM = rewardsAwardedVM; var goals = BL.GetGoals().Where(a => a.ParentUser == current_user).ToList(); var vmlist = new List <ChildRewardVM>(); foreach (var x in goals) { var rewardallocated = testchild.ChildRewards.Where(a => a.GoalId == x.GoalId && a.RewardComplete == false).FirstOrDefault(); int pointsallocated = 0; var cr = new ChildRewardVM(); if (rewardallocated != null) { pointsallocated = rewardallocated.PointsAllocated; cr.WantReward = rewardallocated.RewardRequested; cr.RewardComplete = rewardallocated.RewardComplete; } cr.ChildId = id; cr.GoalCompletePoints = x.GoalPointsRequired; cr.GoalName = x.GoalName; cr.GoalId = x.GoalId; cr.GoalPoints = pointsallocated; // fetch from rewards cr.GoalPointsOriginal = pointsallocated; // fetch from rewards if (pointsallocated == x.GoalPointsRequired) { cr.SliderVisible = false; } else { cr.SliderVisible = true; } vmlist.Add(cr); } model.ChildRewardsVM = vmlist; ViewBag.Child = BL.GetChildForId(id); model.Child = BL.GetChildForId(id); model.Administrator = false; model.UserLevel = true; return(View(model)); }