Beispiel #1
0
        public async Task <IActionResult> Courses(GetCoursesRequest request)
        {
            var location      = CheckLocation(request.Location);
            var shortlistItem = _shortlistCookieService.Get(Constants.ShortlistCookieName);

            var result = await _mediator.Send(new GetCoursesQuery
            {
                Keyword         = request.Keyword,
                RouteIds        = request.Sectors,
                Levels          = request.Levels,
                OrderBy         = request.OrderBy,
                ShortlistUserId = shortlistItem?.ShortlistUserId
            });

            var viewModel = new CoursesViewModel
            {
                Courses            = result.Courses.Select(c => (CourseViewModel)c).ToList(),
                Sectors            = result.Sectors.Select(sector => new SectorViewModel(sector, request.Sectors)).ToList(),
                Total              = result.Total,
                TotalFiltered      = result.TotalFiltered,
                Keyword            = request.Keyword,
                SelectedSectors    = request.Sectors,
                SelectedLevels     = request.Levels,
                Levels             = result.Levels.Select(level => new LevelViewModel(level, request.Levels)).ToList(),
                OrderBy            = request.OrderBy,
                ShortlistItemCount = result.ShortlistItemCount,
                Location           = location?.Name ?? ""
            };

            return(View(viewModel));
        }
Beispiel #2
0
        GetOrchestratorResponseUpdateApprenticeshipViewModelFromCookie(string hashedAccountId,
                                                                       string hashedApprenticeshipId)
        {
            var mappedModel = _apprenticshipsViewModelCookieStorageService.Get(CookieName);

            var apprenticeshipId = _hashingService.DecodeValue(hashedApprenticeshipId);
            var accountId        = _hashingService.DecodeValue(hashedAccountId);

            var apprenticeshipResult = await _mediator.SendAsync(
                new GetApprenticeshipQueryRequest
            {
                AccountId        = accountId,
                ApprenticeshipId = apprenticeshipId
            });

            var apprenticeship = _apprenticeshipMapper.MapToApprenticeshipDetailsViewModel(apprenticeshipResult.Apprenticeship);

            mappedModel.OriginalApprenticeship = apprenticeship;
            mappedModel.HashedAccountId        = hashedAccountId;
            mappedModel.HashedApprenticeshipId = hashedApprenticeshipId;

            return(new OrchestratorResponse <UpdateApprenticeshipViewModel> {
                Data = mappedModel
            });
        }
        public async Task <IActionResult> Index(IndexRequest request)
        {
            IndexRequest savedRequest = null;

            if (request.FromSearch)
            {
                savedRequest = _cookieStorage.Get(CookieNames.ManageApprentices);

                if (savedRequest != null)
                {
                    request = savedRequest;
                }
            }

            if (savedRequest == null)
            {
                _cookieStorage.Update(CookieNames.ManageApprentices, request);
            }

            var viewModel = await _modelMapper.Map <IndexViewModel>(request);

            viewModel.SortedByHeader();

            return(View(viewModel));
        }
Beispiel #4
0
        public FlashMessageViewModel GetFlashMessageViewModelFromCookie()
        {
            var flashMessageViewModelFromCookie = _flashMessage.Get(FlashMessageCookieName);

            _flashMessage.Delete(FlashMessageCookieName);
            return(flashMessageViewModelFromCookie);
        }
        public async Task <ActionResult> CreateAccount()
        {
            var enteredData = _employerAccountOrchestrator.GetCookieData();

            if (enteredData == null)
            {
                // N.B CHANGED THIS FROM SelectEmployer which went nowhere.
                _employerAccountOrchestrator.DeleteCookieData();

                return(RedirectToAction(ControllerConstants.SearchForOrganisationActionName, ControllerConstants.SearchOrganisationControllerName));
            }

            var request = new CreateAccountModel
            {
                UserId                      = GetUserId(),
                OrganisationType            = enteredData.EmployerAccountOrganisationData.OrganisationType,
                OrganisationReferenceNumber = enteredData.EmployerAccountOrganisationData.OrganisationReferenceNumber,
                OrganisationName            = enteredData.EmployerAccountOrganisationData.OrganisationName,
                OrganisationAddress         = enteredData.EmployerAccountOrganisationData.OrganisationRegisteredAddress,
                OrganisationDateOfInception = enteredData.EmployerAccountOrganisationData.OrganisationDateOfInception,
                PayeReference               = enteredData.EmployerAccountPayeRefData.PayeReference,
                AccessToken                 = enteredData.EmployerAccountPayeRefData.AccessToken,
                RefreshToken                = enteredData.EmployerAccountPayeRefData.RefreshToken,
                OrganisationStatus          = string.IsNullOrWhiteSpace(enteredData.EmployerAccountOrganisationData.OrganisationStatus) ? null : enteredData.EmployerAccountOrganisationData.OrganisationStatus,
                EmployerRefName             = enteredData.EmployerAccountPayeRefData.EmployerRefName,
                PublicSectorDataSource      = enteredData.EmployerAccountOrganisationData.PublicSectorDataSource,
                Sector                      = enteredData.EmployerAccountOrganisationData.Sector,
                HashedAccountId             = _accountCookieStorage.Get(_hashedAccountIdCookieName),
                Aorn = enteredData.EmployerAccountPayeRefData.AORN
            };

            var response = await _employerAccountOrchestrator.CreateOrUpdateAccount(request, HttpContext);

            if (response.Status == HttpStatusCode.BadRequest)
            {
                response.Status       = HttpStatusCode.OK;
                response.FlashMessage = new FlashMessageViewModel {
                    Headline = "There was a problem creating your account"
                };
                return(RedirectToAction(ControllerConstants.SummaryActionName));
            }

            _employerAccountOrchestrator.DeleteCookieData();

            var returnUrlCookie = _returnUrlCookieStorageService.Get(ReturnUrlCookieName);

            _accountCookieStorage.Delete(_hashedAccountIdCookieName);

            _returnUrlCookieStorageService.Delete(ReturnUrlCookieName);

            if (returnUrlCookie != null && !returnUrlCookie.Value.IsNullOrWhiteSpace())
            {
                return(Redirect(returnUrlCookie.Value));
            }

            return(RedirectToAction(ControllerConstants.WhenDoYouWantToView, ControllerConstants.EmployerAgreementControllerName, new { hashedAccountId = response.Data.EmployerAgreement.HashedAccountId, agreementId = response.Data.EmployerAgreement.HashedAgreementId }));
        }
Beispiel #6
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (!(context.Controller is Controller controller))
            {
                return;
            }

            var gaData             = new GaData();
            var locationFromCookie = _locationCookieStorageService.Get(Constants.LocationCookieName);

            if (context.HttpContext.Request.Query.TryGetValue("location", out var location))
            {
                gaData.Location = location.ToString();
            }
            else if (locationFromCookie != null)
            {
                if (!string.IsNullOrEmpty(locationFromCookie.Name) && locationFromCookie.Lat != 0 &&
                    locationFromCookie.Lon != 0)
                {
                    gaData.Location = locationFromCookie.Name;
                }
            }


            if (context.RouteData.Values.TryGetValue("providerId", out var providerId))
            {
                if (uint.TryParse(providerId.ToString(), out var ukprn))
                {
                    if (context.HttpContext.Request.Query.TryGetValue("data", out var data))
                    {
                        try
                        {
                            var base64EncodedBytes = WebEncoders.Base64UrlDecode(data);
                            var decoded            = System.Text.Encoding.UTF8.GetString(_protector.Unprotect(base64EncodedBytes));
                            var decodedItems       = decoded.Split("|").ToList();
                            gaData.ProviderId        = ukprn;
                            gaData.ProviderPlacement = Convert.ToInt32(decodedItems.FirstOrDefault());
                            gaData.ProviderTotal     = Convert.ToInt32(decodedItems.LastOrDefault());
                        }
                        catch (FormatException)
                        {
                            _logger.LogInformation("Unable to decode GA data");
                        }
                        catch (CryptographicException)
                        {
                            _logger.LogInformation("Unable to unprotect GA data");
                        }
                    }
                }
            }

            controller.ViewBag.GaData = gaData;

            base.OnActionExecuting(context);
        }
        public async Task <ActionResult> SkipRegistration()
        {
            var request = new CreateUserAccountViewModel
            {
                UserId           = GetUserId(),
                OrganisationName = "MY ACCOUNT"
            };

            var response = await _employerAccountOrchestrator.CreateMinimalUserAccountForSkipJourney(request, HttpContext);

            var returnUrlCookie = _returnUrlCookieStorageService.Get(ReturnUrlCookieName);

            _returnUrlCookieStorageService.Delete(ReturnUrlCookieName);
            if (returnUrlCookie != null && !returnUrlCookie.Value.IsNullOrWhiteSpace())
            {
                return(Redirect(returnUrlCookie.Value));
            }

            return(RedirectToAction(ControllerConstants.IndexActionName, ControllerConstants.EmployerTeamControllerName, new { hashedAccountId = response.Data.HashedId }));
        }
Beispiel #8
0
        private RequestStatus GetRequestStatusFromCookie()
        {
            var status = _lastCohortCookieStorageService.Get(LastCohortPageCookieKey);

            if (string.IsNullOrWhiteSpace(status))
            {
                return(RequestStatus.None);
            }

            return((RequestStatus)Enum.Parse(typeof(RequestStatus), status));
        }
        public async Task <IActionResult> Index([FromQuery] string removed)
        {
            var cookie = _shortlistCookieService.Get(Constants.ShortlistCookieName);

            if (cookie == default)
            {
                return(View(new ShortlistViewModel()));
            }

            var result =
                await _mediator.Send(
                    new GetShortlistForUserQuery { ShortlistUserId = cookie.ShortlistUserId });

            var removedProviderName = string.Empty;

            if (!string.IsNullOrEmpty(removed))
            {
                try
                {
                    var base64EncodedBytes = WebEncoders.Base64UrlDecode(removed);
                    removedProviderName = System.Text.Encoding.UTF8.GetString(_protector.Unprotect(base64EncodedBytes));
                }
                catch (FormatException e)
                {
                    _logger.LogInformation(e, "Unable to decode provider name from request");
                }
                catch (CryptographicException e)
                {
                    _logger.LogInformation(e, "Unable to decode provider name from request");
                }
            }

            var viewModel = new ShortlistViewModel
            {
                Shortlist   = result.Shortlist.Select(item => (ShortlistItemViewModel)item).ToList(),
                Removed     = removedProviderName,
                HelpBaseUrl = _config.EmployerDemandFeatureToggle ? _config.EmployerDemandUrl : ""
            };

            return(View(viewModel));
        }
Beispiel #10
0
        private bool TryGetAccountContext(string hashedAccountId, out AccountContext accountContext)
        {
            if (_accountContext.Get(AccountContextCookieName) is AccountContext accountCookie)
            {
                if (accountCookie.HashedAccountId.Equals(hashedAccountId, StringComparison.InvariantCultureIgnoreCase))
                {
                    accountContext = accountCookie;
                    return(true);
                }
            }

            accountContext = null;
            return(false);
        }
        protected override Task HandleCore(SaveOrganisationData message)
        {
            var existingCookie = _cookieRepository.Get(CookieName);

            if (existingCookie == null)
            {
                createNewCookieWithData(message.OrganisationData);
            }
            else
            {
                updateExistingCookieWithNewData(existingCookie, message.OrganisationData);
            }

            return(Task.CompletedTask);
        }
Beispiel #12
0
        private LocationCookieItem CheckLocation(string location)
        {
            if (location == "-1")
            {
                _locationCookieStorageService.Delete(Constants.LocationCookieName);
                return(null);
            }
            if (string.IsNullOrEmpty(location))
            {
                return(_locationCookieStorageService.Get(Constants.LocationCookieName));
            }

            return(new LocationCookieItem
            {
                Name = location
            });
        }
        public async Task <IActionResult> CreateShortlistItem(CreateShortlistItemRequest request)
        {
            var cookie = _shortlistCookieService.Get(Constants.ShortlistCookieName);

            if (cookie == null)
            {
                cookie = new ShortlistCookieItem
                {
                    ShortlistUserId = Guid.NewGuid()
                };
            }
            _shortlistCookieService.Update(Constants.ShortlistCookieName, cookie, 30);

            var location = _locationCookieService.Get(Constants.LocationCookieName);

            var result = await _mediator.Send(new CreateShortlistItemForUserCommand
            {
                Lat   = location?.Lat,
                Lon   = location?.Lon,
                Ukprn = request.Ukprn,
                LocationDescription = string.IsNullOrEmpty(location?.Name) ? null : location.Name,
                TrainingCode        = request.TrainingCode,
                ShortlistUserId     = cookie.ShortlistUserId
            });

            if (!string.IsNullOrEmpty(request.RouteName))
            {
                return(RedirectToRoute(request.RouteName, new
                {
                    Id = request.TrainingCode,
                    ProviderId = request.Ukprn,
                    Added = string.IsNullOrEmpty(request.ProviderName) ? "" : WebEncoders.Base64UrlEncode(_protector.Protect(
                                                                                                              System.Text.Encoding.UTF8.GetBytes($"{request.ProviderName}")))
                }));
            }

            return(Accepted(result));
        }
Beispiel #14
0
 public virtual EmployerAccountData GetCookieData(HttpContextBase context)
 {
     return(_cookieService.Get(CookieName));
 }
 public virtual EmployerAccountData GetCookieData()
 {
     return(_cookieService.Get(CookieName));
 }
Beispiel #16
0
        public async Task <IActionResult> CourseProviderDetail(int id, int providerId, string location, string removed, string added)
        {
            try
            {
                var locationItem  = CheckLocation(location);
                var shortlistItem = _shortlistCookieService.Get(Constants.ShortlistCookieName);

                var result = await _mediator.Send(new GetCourseProviderQuery
                {
                    ProviderId      = providerId,
                    CourseId        = id,
                    Location        = locationItem?.Name ?? "",
                    Lat             = locationItem?.Lat ?? 0,
                    Lon             = locationItem?.Lon ?? 0,
                    ShortlistUserId = shortlistItem?.ShortlistUserId
                });

                var cookieResult = new LocationCookieItem
                {
                    Name = result.Location,
                    Lat  = result.LocationGeoPoint?.FirstOrDefault() ?? 0,
                    Lon  = result.LocationGeoPoint?.LastOrDefault() ?? 0
                };
                UpdateLocationCookie(cookieResult);

                if (result.Course == null)
                {
                    return(RedirectToRoute(RouteNames.Error404));
                }

                var viewModel = (CourseProviderViewModel)result;
                viewModel.Location = cookieResult.Name;
                var providersRequestCookie = _courseProvidersCookieStorageService.Get(Constants.ProvidersCookieName);
                if (providersRequestCookie != default)
                {
                    if (id != providersRequestCookie.Id)
                    {
                        providersRequestCookie.Id              = id;
                        providersRequestCookie.DeliveryModes   = new List <DeliveryModeType>();
                        providersRequestCookie.ProviderRatings = new List <ProviderRating>();
                    }

                    providersRequestCookie.Location     = result?.Location;
                    viewModel.GetCourseProvidersRequest = providersRequestCookie.ToDictionary();
                }

                if (viewModel.Course.AfterLastStartDate)
                {
                    return(RedirectToRoute(RouteNames.CourseDetails, new { Id = id }));
                }

                var removedProviderFromShortlist =
                    string.IsNullOrEmpty(removed) ? "" : HttpUtility.HtmlDecode(GetEncodedProviderName(removed));
                var addedProviderToShortlist =
                    string.IsNullOrEmpty(added) ? "" : HttpUtility.HtmlDecode(GetEncodedProviderName(added));

                viewModel.BannerUpdateMessage = GetProvidersBannerUpdateMessage(removedProviderFromShortlist, addedProviderToShortlist);

                viewModel.HelpFindingCourseUrl = BuildHelpFindingCourseUrl(viewModel.Course.Id, EntryPoint.ProviderDetail);

                return(View(viewModel));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(RedirectToRoute(RouteNames.Error500));
            }
        }
Beispiel #17
0
 public ApprenticeshipFiltersViewModel GetCookie()
 {
     return(_filterCookieStorageService.Get(nameof(ApprenticeshipFiltersViewModel))
            ?? new ApprenticeshipFiltersViewModel());
 }