Exemple #1
0
        public async Task <ActionResult> StepThreePost([FromForm] StepThreeFormModel form, CancellationToken cancellationToken)
        {
            var user = await _authService.GetCurrentUser(HttpContext, cancellationToken);

            string correctPage = GetCorrectPage(user);

            if (!correctPage.StartsWith("/registration/step-three"))
            {
                // A different step needs to be completed at this point
                return(Redirect(correctPage));
            }

            if (form.HasCustomDistance)
            {
                form.VolunteerDistance = form.CustomDistance;
            }

            var registrationFormVariant = await GetRegistrationJourney(user.ID, cancellationToken);

            try
            {
                _logger.LogInformation($"Step 3 submission for {user.ID}");

                await _userService.CreateUserStepThreeAsync(
                    user.ID,
                    form.VolunteerOptions,
                    form.VolunteerDistance,
                    registrationFormVariant,
                    cancellationToken);

                await _groupMemberService.AddUserToDefaultGroups(user.ID);

                if (user.ReferringGroupId.HasValue && user.ReferringGroupId != -1)
                {
                    return(Redirect($"/community/joinandgo/{Base64Utils.Base64Encode(user.ReferringGroupId.Value)}"));
                }
                else
                {
                    return(Redirect("/account"));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Error executing step 3");
                _logger.LogError(ex.ToString());
                return(Redirect("/registration/step-three?failure=error"));
            }
        }