Exemplo n.º 1
0
        /// <summary>
        /// Finds the clients Address and about information
        /// </summary>
        /// <param name="ClientID"></param>
        /// <returns></returns>
        public async Task <IActionResult> OnGetAsync(int?ClientID)
        {
            //Gets the clients user profile
            var user = await _context.GetClientAsync(this.Username);

            //checks to see if the user is null
            if (user == null)
            {
                return(Redirect("/Error"));
            }

            //Sets client to the users client profile
            var Client = user.Client;


            //Checks to see if client is null
            if (Client == null)
            {
                return(Redirect("/Error"));
            }

            //Assigns clients address to address field
            Address = Client.Address;

            //Assigns clients about to about field
            About = Client.About;

            return(Page());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shows the course data specified for what course the user is in and based off of
        /// the pairing.
        /// </summary>
        /// <param name="courseID"></param>
        /// <returns></returns>
        #region Handlers
        public async Task <IActionResult> OnGetAsync(int courseID)
        {
            //gets the course from the database based off of the course ID.
            Course = await _context.GetCourseAsync(courseID);

            //Gets the Client profile by passing in their username to the GetClientAsync
            //function in the applicationDbContext
            var appUser = await _context.GetClientAsync(Username);

            //Sets the appuser as a Client
            var client = appUser.Client;

            //checks to see if the course exists or if the course exists
            //if not then returns message saying not able to find course id for that specified user
            if (Course == null || client == null)
            {
                return(NotFound($"Unable to course user with ID '{courseID}' for user {Username}"));
            }

            //checks to see if the Client 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.ClientID != client.ID)
            {
                return(NotFound($"Unable to course user with ID '{courseID}' for user {Username}"));
            }

            else
            {
                return(Page());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the pairings associated with the clients and shows the details about them
        /// in the view.
        /// </summary>
        #region Handlers
        public async Task <IActionResult> OnGetAsync()
        {
            //Gets the client account by passing the username to GetClientAsync function in the DAL
            var client = await _context.GetClientAsync(this.Username);

            //Checks to see if user is actually a client if not then returns error
            if (client?.Client == null)
            {
                return(Redirect("/Error"));
            }

            //stores the displaymodel as a list and puts them in display
            this.Display = new List <DisplayModel>();

            //Gets the pairs relating to the client based off of the client ID being passed
            //into the GetClientForProtege function in the ApplicationDbContext file
            var pairs = await _context.GetPairsForClient(client.Client.ID);

            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,
                    ProtegeUserName = pair.Protege?.AppUser?.UserName ?? ""
                };

                this.Display.Add(display);
            }

            return(Page());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            //Checks if the model state is valid
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // Get the Client
            var client = await _context.GetClientAsync(this.Username);

            //Checks to see if the user is actually a client
            if (client?.Client == null)
            {
                return(Redirect("/Error"));
            }

            //gets the client ID
            var clientID = client.Client.ID;

            //Gets the Pair based off of the join code enetered
            Input.ClientJoinCode = new string(Input.ClientJoinCode.Where(jc => !char.IsWhiteSpace(jc)).ToArray());
            var pair = _context.Pair.Where(p => p.JoinCode == Input.ClientJoinCode).SingleOrDefault();

            //sets the pair protege ID to the users protege ID
            pair.ClientID = clientID;

            //Sets the Pair protege form as the user
            pair.Client = client.Client;
            await _context.SaveChangesAsync();

            var clientRole    = new IdentityRole("Client-" + pair.JoinCode);
            var clientSuccess = await _roleManager.CreateAsync(clientRole);

            if (clientSuccess.Succeeded)
            {
                await _userManager.AddToRoleAsync(client, clientRole.Name);
            }

            else
            {
                return(RedirectToPage("/Error"));
            }

            return(RedirectToPage("./Index"));
        }