Beispiel #1
0
        public async Task <IViewComponentResult> InvokeAsync(SelectVenueModel model)
        {
            //var requestModel = new VenueSearchRequestModel { SearchTerm = model.Ukprn.ToString() };
            var requestModel = new VenueSearchRequestModel {
                SearchTerm = _session.GetInt32("UKPRN").Value.ToString()
            };
            var criteria = _venueSearchHelper.GetVenueSearchCriteria(requestModel);
            var result   = await _venueService.SearchAsync(criteria);

            if (result.IsSuccess && result.HasValue)
            {
                var items      = _venueSearchHelper.GetVenueSearchResultItemModels(result.Value.Value);
                var venueItems = new List <VenueItemModel>();
                foreach (var venueSearchResultItemModel in items)
                {
                    venueItems.Add(new VenueItemModel
                    {
                        Id        = venueSearchResultItemModel.Id,
                        VenueName = venueSearchResultItemModel.VenueName
                    });
                }

                model.VenueItems = venueItems;
            }

            if (model.VenueItems.Count() == 1)
            {
                model.VenueItems.First().Checked = true;
            }

            return(View("~/ViewComponents/Courses/SelectVenue/Default.cshtml", model));
        }
        private async Task <VenueSearchResultsViewModel> GetVenues(int ukprn, VenueSearchResultItemModel newVenue, bool updated)
        {
            VenueSearchRequestModel requestModel = new VenueSearchRequestModel
            {
                SearchTerm = ukprn.ToString()
            };

            if (null != newVenue)
            {
                requestModel.NewAddressId = newVenue.Id;
            }


            VenueSearchResultModel model;
            var criteria = _venueSearchHelper.GetVenueSearchCriteria(requestModel);
            var result   = await _venueService.SearchAsync(criteria);

            if (result.IsSuccess)
            {
                var items = _venueSearchHelper.GetVenueSearchResultItemModels(result.Value.Value);
                model = new VenueSearchResultModel(
                    requestModel.SearchTerm,
                    items, newVenue, updated);
            }
            else
            {
                model = new VenueSearchResultModel(result.Error);
            }

            // The v2 EditVenue journey sets a TempData entry after venue has been updated
            if (TempData.ContainsKey(TempDataKeys.UpdatedVenueId))
            {
                model = new VenueSearchResultModel(
                    model.SearchTerm,
                    model.Items,
                    newItem: model.Items.Single(v => v.Id == TempData[TempDataKeys.UpdatedVenueId].ToString()),
                    updated: true);
            }

            var viewModel = new VenueSearchResultsViewModel
            {
                Result = model
            };

            return(viewModel);
        }
        public async Task <IActionResult> Index()
        {
            int UKPRN = 0;

            if (Session.GetInt32("UKPRN").HasValue)
            {
                UKPRN = Session.GetInt32("UKPRN").Value;
            }
            else
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Please select a Provider." }));
            }

            VenueSearchRequestModel requestModel = new VenueSearchRequestModel
            {
                SearchTerm = UKPRN.ToString()
            };
            VenueSearchResultModel model;

            if (requestModel == null)
            {
                model = new VenueSearchResultModel();
            }
            else
            {
                var criteria = _venueSearchHelper.GetVenueSearchCriteria(requestModel);

                var result = await _venueService.SearchAsync(criteria);

                if (result.IsSuccess)
                {
                    var items = _venueSearchHelper.GetVenueSearchResultItemModels(result.Value.Value);
                    model = new VenueSearchResultModel(
                        requestModel.SearchTerm,
                        items, null, false);
                }
                else
                {
                    model = new VenueSearchResultModel(result.Error);
                }
            }

            return(ViewComponent(nameof(ViewComponents.VenueSearchResult.VenueSearchResult), model));
        }
        private async Task <SelectVenueModel> GetVenuesByUkprn(int ukprn)
        {
            var selectVenue = new SelectVenueModel
            {
                LabelText       = "Select course venue",
                HintText        = "Select all that apply.",
                AriaDescribedBy = "Select all that apply.",
                Ukprn           = ukprn
            };
            var requestModel = new VenueSearchRequestModel {
                SearchTerm = ukprn.ToString()
            };
            var criteria = _venueSearchHelper.GetVenueSearchCriteria(requestModel);
            var result   = await _venueService.SearchAsync(criteria);

            if (result.IsSuccess)
            {
                var items      = _venueSearchHelper.GetVenueSearchResultItemModels(result.Value.Value);
                var venueItems = new List <VenueItemModel>();

                foreach (var venueSearchResultItemModel in items)
                {
                    venueItems.Add(new VenueItemModel
                    {
                        Id        = venueSearchResultItemModel.Id,
                        VenueName = venueSearchResultItemModel.VenueName
                    });
                }

                if (venueItems.Count == 1)
                {
                    selectVenue.HintText        = string.Empty;
                    selectVenue.AriaDescribedBy = string.Empty;
                }

                selectVenue.VenueItems = venueItems;
            }

            return(selectVenue);
        }
        public async Task <IActionResult> Index([FromQuery] VenueSearchRequestModel requestModel)
        {
            _session.SetInt32("UKPRN", Convert.ToInt32(requestModel.SearchTerm));


            VenueSearchResultModel model;

            _logger.LogMethodEnter();
            _logger.LogInformationObject("Model", requestModel);

            if (requestModel == null)
            {
                model = new VenueSearchResultModel();
            }
            else
            {
                var criteria = _venueSearchHelper.GetVenueSearchCriteria(
                    requestModel);

                var result = await _venueService.SearchAsync(criteria);

                if (result.IsSuccess && result.HasValue)
                {
                    var items = _venueSearchHelper.GetVenueSearchResultItemModels(result.Value.Value);
                    model = new VenueSearchResultModel(
                        requestModel.SearchTerm,
                        items, null, false);
                }
                else
                {
                    model = new VenueSearchResultModel(result.Error);
                }
            }

            _logger.LogMethodExit();
            return(ViewComponent(nameof(ViewComponents.VenueSearchResult.VenueSearchResult), model));
        }
Beispiel #6
0
        private async Task <VenueSearchResultsViewModel> GetVenues(int ukprn, VenueSearchResultItemModel newVenue, bool updated)
        {
            VenueSearchRequestModel requestModel = new VenueSearchRequestModel
            {
                SearchTerm = ukprn.ToString()
            };

            if (null != newVenue)
            {
                requestModel.NewAddressId = newVenue.Id;
            }


            VenueSearchResultModel model;
            var criteria = _venueSearchHelper.GetVenueSearchCriteria(requestModel);
            var result   = await _venueService.SearchAsync(criteria);

            if (result.IsSuccess)
            {
                var items = _venueSearchHelper.GetVenueSearchResultItemModels(result.Value.Value);
                model = new VenueSearchResultModel(
                    requestModel.SearchTerm,
                    items, newVenue, updated);
            }
            else
            {
                model = new VenueSearchResultModel(result.Error);
            }

            var viewModel = new VenueSearchResultsViewModel
            {
                Result = model
            };

            return(viewModel);
        }
Beispiel #7
0
        public async Task <IActionResult> AddVenueSelectionConfirmation(AddVenueSelectionConfirmationRequestModel requestModel)
        {
            var UKPRN = _session.GetInt32("UKPRN").Value;
            VenueSearchRequestModel mod = new VenueSearchRequestModel();

            mod.SearchTerm = UKPRN.ToString();

            if (requestModel.Id != null)
            {
                Venue venue = new Venue(
                    requestModel.Id,
                    UKPRN,
                    requestModel.VenueName,
                    requestModel.AddressLine1,
                    requestModel.AddressLine2,
                    null,
                    requestModel.TownOrCity,
                    requestModel.County,
                    requestModel.Postcode,
                    VenueStatus.Live,
                    "TestUser",
                    DateTime.Now
                    );

                var updatedVenue = await _venueService.UpdateAsync(venue);

                mod.NewAddressId = updatedVenue.Value.ID;
            }
            else
            {
                Venue venue = new Venue(
                    null,
                    UKPRN,
                    requestModel.VenueName,
                    requestModel.AddressLine1,
                    requestModel.AddressLine2,
                    null,
                    requestModel.TownOrCity,
                    requestModel.County,
                    requestModel.Postcode,
                    VenueStatus.Live,
                    "TestUser",
                    DateTime.Now,
                    DateTime.Now
                    );

                var addedVenue = await _venueService.AddAsync(venue);

                mod.NewAddressId = addedVenue.Value.ID;
            }

            VenueSearchResultModel resultModel;

            var criteria = _venueSearchHelper.GetVenueSearchCriteria(mod);
            var result   = await _venueService.SearchAsync(criteria);

            VenueSearchResultItemModel newItem = new VenueSearchResultItemModel(requestModel.VenueName, requestModel.AddressLine1, requestModel.AddressLine2, requestModel.TownOrCity, requestModel.County, requestModel.Postcode, mod.NewAddressId);

            if (result.IsSuccess && result.HasValue)
            {
                var items = _venueSearchHelper.GetVenueSearchResultItemModels(result.Value.Value);

                if (requestModel.Id != null)
                {
                    resultModel = new VenueSearchResultModel(
                        mod.SearchTerm,
                        items, newItem, true);
                }
                else
                {
                    resultModel = new VenueSearchResultModel(
                        mod.SearchTerm,
                        items, newItem, false);
                }
            }
            else
            {
                resultModel = new VenueSearchResultModel(result.Error);
            }

            var viewModel = new VenueSearchResultsViewModel
            {
                Result = resultModel
            };

            return(View("VenueSearchResults", viewModel));
        }