Пример #1
0
        private async Task CreateOrUpdateProviderQualificationAsync(ProviderVenueQualificationDto providerVenueQualification,
                                                                    int providerVenueId, string postcode, int qualificationId)
        {
            var providerQualificationViewModel =
                await _providerQualificationService.GetProviderQualificationAsync(providerVenueId, qualificationId);

            if (providerQualificationViewModel == null && providerVenueQualification.QualificationIsOffered)
            {
                var addQualificationViewModel = new AddQualificationViewModel
                {
                    LarId           = providerVenueQualification.LarId,
                    QualificationId = qualificationId,
                    Source          = Source,
                    ProviderVenueId = providerVenueId,
                    Postcode        = postcode
                };

                Debug.WriteLine(
                    $">>>> Creating ProviderQualification {addQualificationViewModel.LarId} - {addQualificationViewModel.QualificationId} - {addQualificationViewModel.ProviderVenueId}");
                await _providerQualificationService.CreateProviderQualificationAsync(addQualificationViewModel);
            }
            // Delete Provider Venue Qualification
            else if (providerQualificationViewModel != null && !providerVenueQualification.QualificationIsOffered)
            {
                Debug.WriteLine(
                    $">>>> Removing ProviderQualification {providerVenueId} - {qualificationId} ({providerQualificationViewModel.ProviderVenueId} - {providerQualificationViewModel.QualificationId})");
                await _providerQualificationService.RemoveProviderQualificationAsync(providerVenueId, qualificationId);
            }
        }
        public async Task <IActionResult> CreateQualificationAsync(AddQualificationViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("AddQualification", viewModel));
            }

            var isValid = await _qualificationService.IsValidLarIdAsync(viewModel.LarId);

            if (string.IsNullOrWhiteSpace(viewModel.LarId) || !isValid)
            {
                ModelState.AddModelError("LarId", "Enter a learning aim reference (LAR) that has 8 characters");
                return(View("AddQualification", viewModel));
            }

            var qualification = await _qualificationService.GetQualificationAsync(viewModel.LarId);

            if (qualification == null)
            {
                var isValidLar = await _qualificationService.IsValidOfqualLarIdAsync(viewModel.LarId);

                if (!isValidLar)
                {
                    ModelState.AddModelError("LarId", "You must enter a real learning aim reference (LAR)");
                    return(View("AddQualification", viewModel));
                }

                return(RedirectToRoute("MissingQualification",
                                       new
                {
                    providerVenueId = viewModel.ProviderVenueId,
                    larId = viewModel.LarId
                }));
            }

            viewModel.QualificationId = qualification.Id;
            await _providerQualificationService.CreateProviderQualificationAsync(viewModel);

            return(RedirectToRoute("GetProviderVenueDetail",
                                   new { providerVenueId = viewModel.ProviderVenueId }));
        }