/// <summary> /// Gets the Proteges Address and About Details /// </summary> /// <param name="ProtegeID"></param> /// <returns></returns> public async Task <IActionResult> OnGetAsync(int?ProtegeID) { //Gets the user based off of the username var user = await _context.GetProtegeAsync(this.Username); //Checks to see if user is null if (user == null) { return(Redirect("/Error")); } //Gets the protege profile based on the user var Protege = user.Protege; //Checks to see if protege exists if (Protege == null) { return(Redirect("/Error")); } //Sets the Address to the Protege Address data Address = Protege.Address; //Sets the About to the Protege About data About = Protege.About; return(Page()); }
/// <summary> /// Shows the course data specified for what course the user is in and based off of /// the pairing. /// </summary> /// <param name="courseID"></param> #region DataHandlers public async Task <IActionResult> OnGetAsync(int courseID) { //gets the course ID from the database Course = await _context.GetCourseAsync(courseID); //Gets the Protege profile by passing in their username to the GetProtegeAsync //function in the applicationDbContext var appUser = await _context.GetProtegeAsync(Username); //Sets the appuser as a protege var protege = appUser.Protege; //checks to see if the course exists or if the protege exists //if not then returns message saying not able to find course id for that specified user if (Course == null || protege == null) { return(NotFound($"Unable to course user with ID '{courseID}' for user {Username}")); } //checks to see if the protege ID for the user matches the one associated with course //if not then returns error message telling the user they cannot find the user id for that //course else if (Course.Pair.ProtegeID != protege.ID) { return(NotFound($"Unable to course user with ID '{courseID}' for user {Username}")); } else { return(Page()); } }
/// <summary> /// Gets the Proteges Pairs and shows relevant data pertaining to the pairing. /// </summary> public async Task <IActionResult> OnGetAsync() { //Gets the protege account by passing the username to GetProtegeAsync function in the DAL var protege = await _context.GetProtegeAsync(Username); //Checks to see if user is actually a protege if not then returns error if (protege?.Protege == null) { return(Redirect("/Error")); } //Gets the pairs relating to the protege based off of the protege ID being passed //into the GetPairsForProtege function in the ApplicationDbContext file var pairs = await _context.GetPairsForProtege(protege.Protege.ID); //stores the displaymodel as a list and puts them in display this.Display = new List <DisplayModel>(); foreach (var pair in pairs) { //updates the information of the displaymodel by what is stored for the pairs var display = new DisplayModel { MentorUserName = pair.Mentor?.AppUser?.UserName ?? "", DateCreated = pair.DateCreated.ToShortDateString(), JoinCode = pair.JoinCode, PairID = pair.PairID, ClientUserName = pair.Client?.AppUser?.UserName ?? "" }; this.Display.Add(display); } return(Page()); }
public async Task <IActionResult> OnPostAsync() { //Checks to see if the model state is valid if (!ModelState.IsValid) { return(Page()); } // Get the Protege var protege = await _context.GetProtegeAsync(this.Username); //Checks to see if the user is a data.protege type if not then redirects to an //error if (protege?.Protege == null) { return(Redirect("/Error")); } //gets the protege ID var protegeID = protege.Protege.ID; Input.ProtegeJoinCode = new string(Input.ProtegeJoinCode.Where(jc => !char.IsWhiteSpace(jc)).ToArray()); //Gets the Pair based off of the join code enetered var pair = _context.Pair.Where(p => p.JoinCode == Input.ProtegeJoinCode).SingleOrDefault(); //sets the pair protege ID to the users protege ID pair.ProtegeID = protegeID; //Sets the Pair protege form as the user pair.Protege = protege.Protege; await _context.SaveChangesAsync(); var protegeRole = new IdentityRole("Protege-" + pair.JoinCode); var protegeRoleSucess = await _roleManager.CreateAsync(protegeRole); if (protegeRoleSucess.Succeeded) { await _userManager.AddToRoleAsync(protege, protegeRole.Name); } else { return(RedirectToPage("/Error")); } return(RedirectToPage("./Index")); }