public async Task <IActionResult> AddVenueSelectionConfirmation(AddVenueSelectionConfirmationRequestModel requestModel)
        {
            var UKPRN = Session.GetInt32("UKPRN");

            bool   updated = false;
            string venueID = string.Empty;

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


            var onspd = await GetOnsPostcodeData(requestModel.Postcode);

            var latitude  = onspd.lat;
            var longitude = onspd.@long;

            if (requestModel.Id != null)
            {
                Venue venue = new Venue(
                    requestModel.Id,
                    UKPRN.Value,
                    requestModel.VenueName,
                    requestModel.AddressLine1,
                    (null != requestModel.AddressLine2 ? requestModel.AddressLine2 : string.Empty),
                    null,
                    requestModel.TownOrCity,
                    (null != requestModel.County ? requestModel.County : string.Empty),
                    requestModel.Postcode,
                    latitude,
                    longitude,
                    Live,
                    "TestUser",
                    DateTime.Now
                    );

                var updatedVenue = await _venueService.UpdateAsync(venue);

                updated = true;
                venueID = updatedVenue.Value.ID;
            }
            else
            {
                Venue venue = new Venue(
                    null,
                    UKPRN.Value,
                    requestModel.VenueName,
                    requestModel.AddressLine1,
                    (null != requestModel.AddressLine2 ? requestModel.AddressLine2 : string.Empty),
                    null,
                    requestModel.TownOrCity,
                    (null != requestModel.County ? requestModel.County : string.Empty),
                    requestModel.Postcode,
                    latitude,
                    longitude,
                    Live,
                    "TestUser",
                    DateTime.Now,
                    DateTime.Now
                    );

                var addedVenue = await _venueService.AddAsync(venue);

                venueID = addedVenue.Value.ID;
            }
            //Since we are updating or adding lets pass the model to the GetVenues method
            VenueSearchResultItemModel newItem = new VenueSearchResultItemModel(HtmlEncoder.Default.Encode(requestModel.VenueName), requestModel.AddressLine1, requestModel.AddressLine2, requestModel.TownOrCity, requestModel.County, requestModel.Postcode, venueID);

            var addedVenueModel = new AddedVenueModel
            {
                VenueName    = HtmlEncoder.Default.Encode(requestModel.VenueName),
                AddressLine1 = requestModel.AddressLine1,
                AddressLine2 = requestModel.AddressLine2,
                County       = requestModel.County,
                Id           = venueID,
                PostCode     = requestModel.Postcode,
                Town         = requestModel.TownOrCity
            };


            var returnUrl = Session.GetString("ADDNEWVENUERETURNURL");

            if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
            {
                return(Redirect(new Url(returnUrl).SetQueryParam("venueId", venueID)));
            }


            string option = Session.GetString("Option") ?? string.Empty;

            if (option.ToUpper() == "ADDNEWVENUEFOREDIT")
            {
                Session.SetObject("NewAddedVenue", addedVenueModel);
                return(RedirectToAction("Reload", "EditCourseRun"));
            }

            if (option.ToUpper() == "ADDNEWVENUEFORCOPY")
            {
                Session.SetObject("NewAddedVenue", addedVenueModel);
                return(RedirectToAction("Reload", "CopyCourseRun"));
            }

            if (option.ToUpper() == "ADDNEWVENUE")
            {
                Session.SetObject("NewAddedVenue", addedVenueModel);
                return(RedirectToAction("SummaryToAddCourseRun", "AddCourse"));
            }
            if (option.ToUpper() == "ADDNEWVENUEFORAPPRENTICESHIPS")
            {
                Session.SetObject("NewAddedVenue", addedVenueModel);
                return(RedirectToAction("DeliveryOptions", "Apprenticeships", new
                {
                    message = "",
                    mode = "Add"
                }));
            }
            if (option.ToUpper() == "ADDNEWVENUEFORAPPRENTICESHIPSCOMBINED")
            {
                Session.SetObject("NewAddedVenue", addedVenueModel);
                return(RedirectToAction("DeliveryOptionsCombined", "Apprenticeships", new
                {
                    message = "",
                    mode = "Add"
                }));
            }

            return(View("VenueSearchResults", await GetVenues(UKPRN.Value, newItem, updated)));
        }
Ejemplo n.º 2
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));
        }