public ActionResult GiveBadge() { User signedin = new Models.User(); ViewBag.Message = "Your Give Badge tab page"; signedin = LoginController.GetSessionUser(); return(View(signedin)); }
public ActionResult Index() { if (!LoginController.IsSessionValid()) { return(RedirectToAction("Login", "Login", new { returnUrl = System.Web.HttpContext.Current.Request.Url.PathAndQuery })); } return(View(GetTreeData(LoginController.GetSessionUser().UserId))); }
//pass user recpeient and user sender, get info from those public ActionResult Confirmation(string recepientid, string badgeid, string comment) { Badge newBadge = new Badge(); //get our recepient int recepientID = Int32.Parse(recepientid); User Recepient = new Models.User(); Recepient = Db.Db.GetUser(recepientID); //get our sender //access the user who is logged in User sender = new User(); sender = LoginController.GetSessionUser(); //create a new gift to add to the DB int convertBadgeID = Int32.Parse(badgeid); Gift newGift = new Gift(); DateTime?GiftTime = DateTime.Now; //get the current date newGift.GiftDate = GiftTime; newGift.BadgeId = convertBadgeID; newGift.SenderId = sender.UserId; newGift.RecipientId = Recepient.UserId; newGift.Comment = comment; try { Point location = GetNewBadgeLocation(Recepient); newGift.TreeLocX = location.X; newGift.TreeLocY = location.Y; } catch (Exception e) { // ignore for now } Db.Db.CreateGift(newGift); //add gift to db //create a confdata model for the view ConfirmationData confdata = new ConfirmationData(); confdata.name = Recepient.FirstName + " " + Recepient.LastName; newBadge = Db.Db.GetBadge(convertBadgeID); confdata.badge = newBadge.Name; confdata.comment = comment; // confdata.username = sender. + " " + sender.lastname; //Do query to get the email connected to the name EmailManager.SendTextEmail(comment, "YOU RECIEVED A BADGE", Recepient.Email, "GSTBADGESYSTEM", "noreply", response => { }); return(View(confdata)); }
public ActionResult Home() { if (!LoginController.IsSessionValid()) { return(RedirectToAction("Login", "Login", new { returnUrl = System.Web.HttpContext.Current.Request.Url.PathAndQuery })); } User curUser = LoginController.GetSessionUser(); //go to the tree view if it's a student if (curUser.UserType == UserType.Student) { return(RedirectToAction("Index")); } return(View(curUser)); }
public ActionResult GridIndex() { User student = LoginController.GetSessionUser(); int shortList = 0; int nextList = 0; int longest = 0; // keeps track of the longest list of badges GridViewModel GVM = new GridViewModel(); List <List <BadgeViewModel> > allBadgesList = new List <List <BadgeViewModel> >(); List <Badge> tempCoreList = Db.Db.GetBadges(BadgeType.Apple); int i = 0; foreach (Badge b in tempCoreList) { BadgeViewModel tempBVM = new BadgeViewModel(); tempBVM.badge = b; allBadgesList.Add(new List <BadgeViewModel>()); // 1 list per core allBadgesList[i].Add(tempBVM); List <Badge> tempCompList = Db.Db.GetPrerequisites(b.BadgeId); foreach (Badge c in tempCompList) { BadgeViewModel tempCompBadge = new BadgeViewModel(); tempCompBadge.badge = c; allBadgesList[i].Add(tempCompBadge); // add all of a core's prereqs to its list } // end foreach c i++; // move to the next list } // end foreach b // keep track of shortest list for (int j = 0; j < allBadgesList.Count; j++) { if (allBadgesList[j].Count < allBadgesList[shortList].Count) { nextList = shortList; shortList = j; } // end if count } //////////////////////////////////// // The badges the user actually has //////////////////////////////////// List <Gift> tempGiftList = Db.Db.GetGiftsGivenTo(student.UserId); List <Badge> tempGCores = new List <Badge>(); List <Badge> tempGComps = new List <Badge>(); List <Badge> tempComendsHold = new List <Badge>(); List <Badge> tempGComends; foreach (Gift g in tempGiftList) { switch (g.BadgeGift.Type) { case BadgeType.Apple: tempGCores.Add(g.BadgeGift); break; case BadgeType.Flower: tempGComps.Add(g.BadgeGift); break; case BadgeType.Leaf: tempComendsHold.Add(g.BadgeGift); break; default: Console.WriteLine("How'd we get this wrong?"); break; } } tempGComends = tempComendsHold.GroupBy(p => p.BadgeId).Select(g => g.First()).ToList(); // make sure to only show each comend badge once // activate cores and competencies that are obtained foreach (Badge core in tempGCores) { foreach (List <BadgeViewModel> relList in allBadgesList) { if (relList[0].badge.BadgeId == core.BadgeId) { foreach (BadgeViewModel bvm in relList) { bvm.obtained = true; // if you have a core, you have all its competencies } // end foreach bvm } // end if } // end foreach relList } // end foreach core // activate all competencies that aren't associated with an activated core foreach (Badge comp in tempGComps) { foreach (List <BadgeViewModel> relList in allBadgesList) { foreach (BadgeViewModel bvm in relList) { if (bvm.badge.BadgeId == comp.BadgeId) { bvm.obtained = true; } } // end foreach bvm } // end foreach relList } // end foreach comp // add all comendation badges to the list list foreach (Badge comend in tempGComends) { BadgeViewModel tempCBVM = new BadgeViewModel(); tempCBVM.obtained = true; tempCBVM.badge = comend; allBadgesList[shortList].Add(tempCBVM); // keep track of the shortest list if (allBadgesList[shortList].Count >= allBadgesList[0].Count) { shortList = 0; for (int index = 0; index < allBadgesList.Count; index++) { if (allBadgesList[shortList].Count > allBadgesList[index].Count) { shortList = index; } // end if } // end for } // end if } // end foreach comend // at this point, we have a list of lists w/ counts that are w/i 1 element of each other in length for (int j = 0; j < allBadgesList.Count; j++) { if (allBadgesList[j].Count > allBadgesList[longest].Count) { longest = j; } } GVM.student = student; GVM.grid = allBadgesList; GVM.longest = longest; return(View(GVM)); }