public async Task <IActionResult> OnPostAsync()
        {
            ModelState.ClearValidationState(nameof(NewPasswordRepeat));
            if (NewPasswordRepeat == NewPassword)
            {
                ModelState.MarkFieldValid(nameof(NewPasswordRepeat));
            }
            else
            {
                ModelState.AddModelError(nameof(NewPasswordRepeat), "Kodeordene er ikke ens.");
            }

            bool emailValid = true;

            if (UserEmail.Length < 5)
            {
                emailValid = false;
            }
            if (UserEmail.Split('.').Length != 2)
            {
                emailValid = false;
            }
            if (UserEmail.Split('@').Length != 2)
            {
                emailValid = false;
            }
            if (UserEmail.IndexOf('.') < UserEmail.IndexOf('@'))
            {
                emailValid = false;
            }

            if (emailValid)
            {
                ModelState.MarkFieldValid(nameof(UserEmail));
            }
            else
            {
                ModelState.AddModelError(nameof(UserEmail), "Ugyldig Email");
            }

            if (UserName.Length > 0)
            {
                ModelState.MarkFieldValid(nameof(UserName));
            }

            if (IsNewUser)
            {
                ModelState.Remove(nameof(CurrentPassword));
            }
            //ModelState.MarkFieldValid(nameof(CurrentPassword));

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (IsNewUser)
            {
                CurrentUser          = new User();
                CurrentUser.Password = NewPassword;

                int firstnameInd = UserName.IndexOf(' ') + 1;
                if (firstnameInd != 0)
                {
                    CurrentUser.FirstName = UserName.Substring(0, firstnameInd - 1);
                    CurrentUser.LastName  = UserName.Substring(firstnameInd, UserName.Length - firstnameInd);
                }
                else
                {
                    CurrentUser.FirstName = UserName;
                    CurrentUser.LastName  = UserName;
                }
                CurrentUser.Email = UserEmail;
                if (UserPrefs != null)
                {
                    CurrentUser.Preference = UserPrefs.Split(',').ToList();
                }
                else
                {
                    CurrentUser.Preference = new List <string>();
                }

                int?conferenceIdtest = _sessionService.GetConferenceId(HttpContext.Session);
                if (conferenceIdtest == null)
                {
                    return(BadRequest());
                }


                _userService.ClearItemData();
                User test = await _userService.GetFromField(CurrentUser.Identity(UserEmail));

                if (test != null)
                {
                    EmailExist = true;
                    return(Page());
                }
                await _userService.Create(CurrentUser);

                UserConferenceBinding userCon = new UserConferenceBinding();

                userCon.ConferenceId = (int)conferenceIdtest;

                test = await _userService.GetFromField(CurrentUser.Identity(UserEmail));

                userCon.UserId = test.UserId;
                await _userConService.Create(userCon);

                //_UserCon.ConferenceId = currentConferenceId;
                // _userConService
                _sessionService.SetUserId(HttpContext.Session, test.UserId);

                return(RedirectToPage("/index"));
            }

            CurrentUserId = _sessionService.GetUserId(HttpContext.Session);

            if (CurrentUserId > 0)
            {
                CurrentUser = await _userService.GetFromId((int)_sessionService.GetUserId(HttpContext.Session));

                if (CurrentUser.Password == CurrentPassword)
                {
                    CurrentUser.Password = NewPassword;
                    PasswordUpdated      = await _userService.Update(CurrentUser);
                }
                else
                {
                    WrongPassword = true;
                }
            }
            else
            {
                return(BadRequest());
            }

            return(Page());
        }