public ActionResult CreateProviderSiteRelationship(ProviderSiteViewModel viewModel) { var response = _adminMediator.CreateProviderSiteRelationship(viewModel); ModelState.Clear(); SetUserMessage(response.Message); switch (response.Code) { case AdminMediatorCodes.CreateProviderSiteRelationship.FailedValidation: response.ValidationResult.AddToModelState(ModelState, "SearchViewModel"); return(View("ProviderSite", response.ViewModel)); case AdminMediatorCodes.CreateProviderSiteRelationship.InvalidUkprn: return(RedirectToRoute(ManagementRouteNames.AdminViewProviderSite, new { viewModel.ProviderSiteId })); case AdminMediatorCodes.CreateProviderSiteRelationship.Error: return(RedirectToRoute(ManagementRouteNames.AdminViewProviderSite, new { viewModel.ProviderSiteId })); case AdminMediatorCodes.CreateProviderSiteRelationship.Ok: return(RedirectToRoute(ManagementRouteNames.AdminViewProviderSite, new { viewModel.ProviderSiteId })); default: throw new InvalidMediatorCodeException(response.Code); } }
public ProviderSiteViewModel SaveProviderSite(ProviderSiteViewModel viewModel) { var providerSite = _providerService.GetProviderSite(viewModel.ProviderSiteId); //Copy over changes providerSite.FullName = viewModel.FullName; providerSite.TradingName = viewModel.TradingName; providerSite.EmployerDescription = viewModel.EmployerDescription; providerSite.CandidateDescription = viewModel.CandidateDescription; providerSite.ContactDetailsForEmployer = viewModel.ContactDetailsForEmployer; providerSite.ContactDetailsForCandidate = viewModel.ContactDetailsForCandidate; providerSite.TrainingProviderStatus = viewModel.TrainingProviderStatus; if (viewModel.ProviderSiteRelationships != null) { foreach (var providerSiteRelationshipViewModel in viewModel.ProviderSiteRelationships) { var providerSiteRelationship = providerSite.ProviderSiteRelationships.SingleOrDefault(psr => psr.ProviderSiteRelationshipId == providerSiteRelationshipViewModel.ProviderSiteRelationshipId); if (providerSiteRelationship != null) { providerSiteRelationship.ProviderSiteRelationShipTypeId = providerSiteRelationshipViewModel.ProviderSiteRelationshipType; } } } var updatedProviderSite = _providerService.SaveProviderSite(providerSite); return(ProviderMappers.Map <ProviderSite, ProviderSiteViewModel>(updatedProviderSite)); }
public ProviderSiteViewModel CreateProviderSiteRelationship(ProviderSiteViewModel viewModel, int providerId) { var providerSiteRelationship = new ProviderSiteRelationship { ProviderId = providerId, ProviderSiteId = viewModel.ProviderSiteId, ProviderSiteRelationShipTypeId = viewModel.ProviderSiteRelationshipType }; _providerService.CreateProviderSiteRelationship(providerSiteRelationship); return(GetProviderSiteViewModel(viewModel.ProviderSiteId)); }
public MediatorResponse <ProviderSiteViewModel> SaveProviderSite(ProviderSiteViewModel viewModel) { try { viewModel = _providerProvider.SaveProviderSite(viewModel); return(GetMediatorResponse(AdminMediatorCodes.SaveProviderSite.Ok, viewModel, ProviderSiteViewModelMessages.ProviderSiteSavedSuccessfully, UserMessageLevel.Info)); } catch (Exception ex) { _logService.Error($"Failed to save provider site with id={viewModel.ProviderSiteId}", ex); viewModel = _providerProvider.GetProviderSiteViewModel(viewModel.ProviderSiteId); return(GetMediatorResponse(AdminMediatorCodes.SaveProviderSite.Error, viewModel, ProviderSiteViewModelMessages.ProviderSiteSaveError, UserMessageLevel.Error)); } }
public MediatorResponse <ProviderSiteViewModel> CreateProviderSite(ProviderSiteViewModel viewModel) { var validatonResult = _providerSiteViewModelServerValidator.Validate(viewModel); if (!validatonResult.IsValid) { return(GetMediatorResponse(AdminMediatorCodes.CreateProviderSite.FailedValidation, viewModel, validatonResult)); } var existingViewModel = _providerProvider.GetProviderSiteViewModel(viewModel.EdsUrn); if (existingViewModel != null) { return(GetMediatorResponse(AdminMediatorCodes.CreateProviderSite.EdsUrnAlreadyExists, viewModel, ProviderSiteViewModelMessages.EdsUrnAlreadyExists, UserMessageLevel.Error)); } viewModel = _providerProvider.CreateProviderSite(viewModel); return(GetMediatorResponse(AdminMediatorCodes.CreateProviderSite.Ok, viewModel, ProviderSiteViewModelMessages.ProviderSiteCreatedSuccessfully, UserMessageLevel.Info)); }
public static ProviderSiteViewModel Convert(this ProviderSite providerSite) { var viewModel = new ProviderSiteViewModel { ProviderSiteId = providerSite.ProviderSiteId, EdsUrn = providerSite.EdsUrn, FullName = providerSite.FullName, TradingName = providerSite.TradingName, EmployerDescription = providerSite.EmployerDescription, CandidateDescription = providerSite.CandidateDescription, ContactDetailsForEmployer = providerSite.ContactDetailsForEmployer, ContactDetailsForCandidate = providerSite.ContactDetailsForCandidate, Address = providerSite.Address.Convert(), WebPage = providerSite.WebPage, TrainingProviderStatus = providerSite.TrainingProviderStatus, ProviderSiteRelationships = providerSite.ProviderSiteRelationships.Select(psr => psr.Convert()).ToList() }; return(viewModel); }
public ProviderSiteViewModel CreateProviderSite(ProviderSiteViewModel viewModel) { var providerSite = ProviderMappers.Map <ProviderSiteViewModel, ProviderSite>(viewModel); //Create a relationship between the provider and new provider site providerSite.ProviderSiteRelationships = new List <ProviderSiteRelationship> { new ProviderSiteRelationship { ProviderId = viewModel.ProviderId, ProviderSiteRelationShipTypeId = ProviderSiteRelationshipTypes.Owner } }; providerSite.TrainingProviderStatus = EmployerTrainingProviderStatuses.Activated; providerSite = _providerService.CreateProviderSite(providerSite); var providerSiteViewModel = ProviderMappers.Map <ProviderSite, ProviderSiteViewModel>(providerSite); providerSiteViewModel.ProviderId = viewModel.ProviderId; return(providerSiteViewModel); }
public MediatorResponse <ProviderSiteViewModel> CreateProviderSiteRelationship(ProviderSiteViewModel viewModel) { var existingViewModel = _providerProvider.GetProviderSiteViewModel(viewModel.ProviderSiteId); existingViewModel.ProviderUkprn = viewModel.ProviderUkprn; existingViewModel.ProviderSiteRelationshipType = viewModel.ProviderSiteRelationshipType; viewModel = existingViewModel; var validatonResult = _providerSiteRelationshipViewModelServerValidator.Validate(viewModel); if (!validatonResult.IsValid) { return(GetMediatorResponse(AdminMediatorCodes.CreateProviderSiteRelationship.FailedValidation, viewModel, validatonResult)); } var providerViewModel = _providerProvider.GetProviderViewModel(viewModel.ProviderUkprn); if (providerViewModel == null) { return(GetMediatorResponse(AdminMediatorCodes.CreateProviderSiteRelationship.InvalidUkprn, viewModel, ProviderSiteViewModelMessages.ProviderSiteRelationshipInvalidUkprn, UserMessageLevel.Error)); } try { viewModel = _providerProvider.CreateProviderSiteRelationship(viewModel, providerViewModel.ProviderId); return(GetMediatorResponse(AdminMediatorCodes.CreateProviderSiteRelationship.Ok, viewModel, ProviderSiteViewModelMessages.ProviderSiteRelationshipCreatedSuccessfully, UserMessageLevel.Info)); } catch (Exception ex) { _logService.Error($"Failed to create provider site relationship for provider site with id={viewModel.ProviderSiteId}", ex); return(GetMediatorResponse(AdminMediatorCodes.CreateProviderSiteRelationship.Error, viewModel, ProviderSiteViewModelMessages.ProviderSiteRelationshipCreationError, UserMessageLevel.Error)); } }