Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            SouthostingUser = await _userManager.FindByIdAsync(id);

            SouthostingUser.FirstName = Input.FirstName;
            SouthostingUser.LastName  = Input.LastName;
            SouthostingUser.Email     = Input.Email;

            _context.Attach(SouthostingUser).State = EntityState.Modified;

            var oldRole = (await _userManager.GetRolesAsync(SouthostingUser)).FirstOrDefault();

            if (Input.Role != oldRole)
            {
                await _userManager.RemoveFromRoleAsync(SouthostingUser, oldRole);

                await _userManager.AddToRoleAsync(SouthostingUser, Input.Role);
            }

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SouthostingUser = await _userManager.FindByIdAsync(id);

            if (SouthostingUser == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SouthostingUser = await _userManager.FindByIdAsync(id);

            if (SouthostingUser != null)
            {
                await _userManager.DeleteAsync(SouthostingUser);
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/Adverts");
            if (ModelState.IsValid)
            {
                var user = new SouthostingUser {
                    FirstName = Input.FirstName,
                    LastName  = Input.LastName,
                    UserName  = Input.Email,
                    Email     = Input.Email
                };
                var role = Input.Role;
                if (role != Constants.StudentRole && role != Constants.LandlordRole)
                {
                    // they've sent a different role
                    ModelState.AddModelError(string.Empty, "Invalid role. Pick from: Student, Landlord.");
                    return(Page());
                }

                var result = await _userManager.CreateAsync(user, Input.Password);

                var roleResult = await _userManager.AddToRoleAsync(user, role);

                if (result.Succeeded && roleResult.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SouthostingUser = await _userManager.FindByIdAsync(id);

            if (SouthostingUser == null)
            {
                return(NotFound());
            }

            RoleOptions = new List <SelectListItem> {
                new SelectListItem {
                    Value = Constants.StudentRole, Text = Constants.StudentRole
                },
                new SelectListItem {
                    Value = Constants.LandlordRole, Text = Constants.LandlordRole
                },
                new SelectListItem {
                    Value = Constants.AccommodationOfficerRole, Text = Constants.AccommodationOfficerRole
                },
                new SelectListItem {
                    Value = Constants.AdministratorRole, Text = Constants.AdministratorRole
                }
            };

            Input = new InputModel {
                Id        = SouthostingUser.Id,
                FirstName = SouthostingUser.FirstName,
                LastName  = SouthostingUser.LastName,
                Email     = SouthostingUser.Email,
                Role      = (await _userManager.GetRolesAsync(SouthostingUser)).FirstOrDefault()
            };

            return(Page());
        }