public async Task <IActionResult> CreateVenueAsync(AddProviderVenueViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("AddProviderVenue", viewModel));
            }

            var(isValid, formattedPostcode) = await _providerVenueService.IsValidPostcodeAsync(viewModel.Postcode);

            viewModel.Postcode = formattedPostcode;

            if (string.IsNullOrWhiteSpace(viewModel.Postcode) || !isValid)
            {
                ModelState.AddModelError("Postcode", "You must enter a real postcode");
                return(View("AddProviderVenue", viewModel));
            }

            var venue = await _providerVenueService.GetVenueAsync(viewModel.ProviderId, viewModel.Postcode);

            int venueId;

            if (venue != null)
            {
                venueId = venue.Id;
            }
            else
            {
                venueId = await _providerVenueService.CreateVenueAsync(viewModel);
            }

            return(RedirectToRoute("GetProviderVenueDetail", new { providerVenueId = venueId }));
        }
Example #2
0
        private async Task <ProviderVenueDetailViewModel> CreateOrUpdateProviderVenueAsync(ProviderVenueQualificationDto providerVenueQualification, int providerId)
        {
            if (string.IsNullOrEmpty(providerVenueQualification.VenuePostcode))
            {
                return(null);
            }

            var venueViewModel = await _providerVenueService.GetVenueWithTrimmedPostcodeAsync(providerId,
                                                                                              providerVenueQualification.VenuePostcode);

            if (venueViewModel == null)
            {
                var addProviderVenue = new AddProviderVenueViewModel
                {
                    ProviderId = providerId,
                    Postcode   = providerVenueQualification.VenuePostcode,
                    Source     = Source
                };

                var venueId = await _providerVenueService.CreateVenueAsync(addProviderVenue);

                Debug.WriteLine(
                    $"Created venue with id {venueId} for provider {providerId} and postcode {providerVenueQualification.VenuePostcode}");

                venueViewModel = await _providerVenueService.GetVenueAsync(venueId);
            }

            var providerVenueValidator = ValidateProviderVenueToUpdate(venueViewModel, providerVenueQualification);

            if (providerVenueValidator.IsUpdated)
            {
                await _providerVenueService.UpdateVenueAsync(providerVenueValidator.ProviderVenueDetailViewModel);
            }

            // Provider Venue Delete
            if (venueViewModel.IsRemoved != providerVenueQualification.VenueIsRemoved)
            {
                var removeProviderVenueViewModel = new RemoveProviderVenueViewModel
                {
                    Postcode        = venueViewModel.Postcode,
                    ProviderId      = venueViewModel.ProviderId,
                    ProviderVenueId = venueViewModel.Id
                };

                if (providerVenueQualification.VenueIsRemoved)
                {
                    await _providerVenueService.UpdateVenueAsync(removeProviderVenueViewModel);
                }
                else
                {
                    await _providerVenueService.UpdateVenueToNotRemovedAsync(removeProviderVenueViewModel);
                }
            }

            return(venueViewModel);
        }
        public When_ProviderVenueQualificationService_Is_Called_With_New_ProviderVenue()
        {
            var providerService = Substitute.For <IProviderService>();

            _providerVenueService             = Substitute.For <IProviderVenueService>();
            _providerQualificationService     = Substitute.For <IProviderQualificationService>();
            _qualificationRouteMappingService = Substitute.For <IQualificationRouteMappingService>();
            _qualificationService             = Substitute.For <IQualificationService>();
            _routePathService = Substitute.For <IRoutePathService>();

            providerService.SearchAsync(10000001)
            .Returns((ProviderSearchResultDto)null);

            providerService.CreateProviderAsync(Arg.Any <CreateProviderDetailViewModel>()).Returns(1);
            _providerVenueService.CreateVenueAsync(Arg.Any <AddProviderVenueViewModel>()).Returns(1);

            _providerVenueService
            .GetVenueWithTrimmedPostcodeAsync(1, "CV1 2WT")
            .Returns((ProviderVenueDetailViewModel)null);

            _providerVenueService
            .GetVenueAsync(1)
            .Returns(new ProviderVenueDetailViewModel
            {
                Id                   = 1,
                ProviderId           = 1,
                Postcode             = "CV1 2WT",
                IsEnabledForReferral = true,
                Source               = "Import",
                Qualifications       = new List <QualificationDetailViewModel>()
            });

            _qualificationService.GetQualificationAsync(Arg.Any <string>()).Returns((QualificationDetailViewModel)null);
            _providerQualificationService.GetProviderQualificationAsync(Arg.Any <int>(), Arg.Any <int>()).Returns((ProviderQualificationDto)null);
            _routePathService.GetRouteSummaryByNameAsync(Arg.Any <string>()).Returns((RouteSummaryViewModel)null);

            var providerVenueQualificationService = new ProviderVenueQualificationService
                                                    (
                providerService,
                _providerVenueService,
                _providerQualificationService,
                _qualificationService,
                _routePathService,
                _qualificationRouteMappingService
                                                    );

            var dtoList = new ValidProviderVenueQualificationDtoListBuilder()
                          .AddVenue()
                          .Build();

            _results = providerVenueQualificationService.UpdateAsync(dtoList).GetAwaiter().GetResult();
        }
Example #4
0
        public When_ProviderVenue_Add_Venue_Does_Not_Exist()
        {
            _providerVenueService = Substitute.For <IProviderVenueService>();
            _providerVenueService.IsValidPostcodeAsync("CV1 2WT").Returns((true, "CV1 2WT"));
            _providerVenueService.GetVenueAsync(1, "CV1 2WT").ReturnsNull();
            _providerVenueService.CreateVenueAsync(Arg.Any <AddProviderVenueViewModel>()).Returns(1);

            var providerVenueController = new ProviderVenueController(_providerVenueService);
            var controllerWithClaims    = new ClaimsBuilder <ProviderVenueController>(providerVenueController)
                                          .AddUserName("username")
                                          .AddEmail("*****@*****.**")
                                          .Build();

            var viewModel = new AddProviderVenueViewModel
            {
                ProviderId = 1,
                Postcode   = "CV1 2WT"
            };

            _result = controllerWithClaims.CreateVenueAsync(viewModel).GetAwaiter().GetResult();
        }