/// <summary> /// This method deletes a provider /// </summary> /// <param name="Id"></param> /// <returns></returns> public async Task <bool> DeleteProvider(int Id) { bool result = false; if (Id > 0) { var a = await providerRepository.GetAsync(Id); if (a != null) { try { providerRepository.DeleteById(a); } catch (Exception ex) { throw ex; } } } return(result); }
public async Task <IActionResult> Post([FromBody] Provider provider) { if (provider is null) { throw new ArgumentNullException(nameof(provider)); } var validation = new ProviderValidator().Validate(provider); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ToActionResult()); } var providerDocument = await ProviderRepository .GetAsync(provider.Id) .ConfigureAwait(false); if (providerDocument != null) { return(ErrorResult .Conflict($"A Provider with the ID '{provider.Id}' already exists on this TeamCloud Instance. Please try your request again with a unique ID or call PUT to update the existing Provider.") .ToActionResult()); } if (provider.Type == ProviderType.Virtual) { var serviceProviders = await ProviderRepository .ListAsync(providerType : ProviderType.Service) .ToListAsync() .ConfigureAwait(false); var serviceProvider = serviceProviders .FirstOrDefault(p => provider.Id.StartsWith($"{p.Id}.", StringComparison.Ordinal)); if (serviceProvider is null) { var validServiceProviderIds = string.Join(", ", serviceProviders.Select(p => p.Id)); return(ErrorResult .BadRequest(new ValidationError { Field = "id", Message = $"No matching service provider found. Virtual provider ids must begin with the associated Service provider id followed by a period (.). Available service providers: {validServiceProviderIds}" }) .ToActionResult()); } var urlPrefix = $"{serviceProvider.Url}?"; if (!provider.Url.StartsWith(urlPrefix, StringComparison.OrdinalIgnoreCase)) { return(ErrorResult .BadRequest(new ValidationError { Field = "url", Message = $"Virtual provider url must match the associated service provider url followed by a query string. The url should begin with {urlPrefix}" }) .ToActionResult()); } } var currentUser = await UserService .CurrentUserAsync() .ConfigureAwait(false); providerDocument = new ProviderDocument() .PopulateFromExternalModel(provider); var command = new OrchestratorProviderCreateCommand(currentUser, providerDocument); return(await Orchestrator .InvokeAndReturnActionResultAsync <ProviderDocument, Provider>(command, Request) .ConfigureAwait(false)); }