public ActionResult GroupSummary(string courseCode) { GroupListModel glm = new GroupListModel(); currentCourseCode = courseCode; glm.CourseCode = courseCode; glm.SuggestedGroups = null; glm.AllGroups = null; GroupSummaryForUser gsfu = _groupCom.GetGroupSummary(User.Identity.Name, courseCode); if (gsfu != null) { //if(string.IsNullOrWhiteSpace(gsfu.registeredGroupCode)) //show group summary //{ if (gsfu.registeredGroup != null) { glm.registeredGroup = new GT.BuddyUp.WebApp.Models.GroupSummary() { GroupCode = gsfu.registeredGroup.GroupCode, GroupName = gsfu.registeredGroup.GroupName, Objective = gsfu.registeredGroup.Objective, TimeZone = gsfu.registeredGroup.activeTimeZone }; } if (gsfu.suggestedGroups != null && gsfu.suggestedGroups.Count > 0) { glm.SuggestedGroups = new List <GT.BuddyUp.WebApp.Models.GroupSummary>(); foreach (var grp in gsfu.suggestedGroups) { glm.SuggestedGroups.Add(new GT.BuddyUp.WebApp.Models.GroupSummary() { GroupCode = grp.GroupCode, GroupName = grp.GroupName, TimeZone = grp.activeTimeZone, Objective = grp.Objective }); } } if (gsfu.AllGroups != null && gsfu.AllGroups.Count > 0) { glm.AllGroups = new List <GT.BuddyUp.WebApp.Models.GroupSummary>(); foreach (var grp in gsfu.AllGroups) { glm.AllGroups.Add(new GT.BuddyUp.WebApp.Models.GroupSummary() { GroupCode = grp.GroupCode, GroupName = grp.GroupName, TimeZone = grp.activeTimeZone, Objective = grp.Objective }); } } return(View(glm)); //} //else//redirect to group detail page //{ // return RedirectToAction("GroupDetail", "Group", routeValues: new { groupCode = gsfu.registeredGroupCode }); //} } ModelState.AddModelError("", "Oops! Something wrong happened! Please try again."); return(View(glm)); }
public GroupSummaryForUser GetGroupSummary(string userEmail, string courseCode) { GroupSummaryForUser gsfu = new GroupSummaryForUser(); AspNetUsers up = _repUserProfile.Get(filter: f => f.Email == userEmail).FirstOrDefault(); Course course = _repCourse.Get(filter: f => f.CourseCode == courseCode, includes: "Groups,CourseUserRoles").FirstOrDefault(); EntityModel.CourseUser cur = _repCourseUserRole.Get(filter: f => f.CourseId == course.CourseId && f.UserId == up.Id, includes: "Group").FirstOrDefault(); if (cur.GroupId.HasValue) { gsfu.registeredGroup = new GroupSummary() { GroupCode = cur.Group.GroupCode, GroupName = cur.Group.GroupName, activeTimeZone = cur.Group.TimeZone, Objective = cur.Group.Objective }; } else { gsfu.registeredGroup = null; } List <string> answers = cur.AnswerSet.Split(',').ToList(); gsfu.suggestedGroups = new List <GroupSummary>(); foreach (EntityModel.CourseUser cu in course.CourseUserRoles) { if (cu.UserId != up.Id && !string.IsNullOrWhiteSpace(cu.AnswerSet)) { int matchPercentage = getMatchPercentage(answers, cu.AnswerSet.Split(',').ToList()); if (matchPercentage >= 50) { if (cu.GroupId.HasValue) { if (!cur.GroupId.HasValue || cur.GroupId != cu.GroupId) { Group grp = _repGroup.Get(filter: f => f.GroupId == cu.GroupId).FirstOrDefault(); if (!gsfu.suggestedGroups.Any(x => x.GroupCode == grp.GroupCode)) { gsfu.suggestedGroups.Add(new GroupSummary() { GroupName = grp.GroupName, GroupCode = grp.GroupCode, Objective = grp.Objective, activeTimeZone = grp.TimeZone }); } } } } } } gsfu.AllGroups = new List <GroupSummary>(); foreach (var grp in course.Groups) { if (!cur.GroupId.HasValue || cur.GroupId != grp.GroupId) { gsfu.AllGroups.Add(new GroupSummary() { GroupCode = grp.GroupCode, GroupName = grp.GroupName, Objective = grp.Objective, activeTimeZone = grp.TimeZone }); } } return(gsfu); }