/// <summary> /// Validates general description model. /// </summary> /// <param name="request"></param> /// <param name="createOperation"></param> protected void ValidateParameters(IVmOpenApiGeneralDescriptionInVersionBase request, bool createOperation = true) { IList <string> newLanguages = new List <string>(); if (createOperation) { newLanguages = request.AvailableLanguages; } else { var currentVersion = generalDescriptionService.GetGeneralDescriptionVersionBase(request.Id.Value, 0, false); if (currentVersion == null || string.IsNullOrEmpty(currentVersion.PublishingStatus)) { this.ModelState.AddModelError("General description id", $"Version for service with id '{request.Id.Value}' not found."); } else { request.CurrentPublishingStatus = currentVersion.PublishingStatus; // Get the available languages from current version // Check if user has added new language versions. New available languages and data need to be validated (required fields need to exist in request). newLanguages = request.AvailableLanguages.Where(i => !currentVersion.AvailableLanguages.Contains(i)).ToList(); request.CurrentVersionId = currentVersion.CurrentVersionId; } } GeneralDescriptionValidator service = new GeneralDescriptionValidator(request, codeService, fintoService, newLanguages, createOperation); service.Validate(this.ModelState); }
/// <summary> /// Creates a new general description with the data provided as input. /// </summary> /// <param name="request"></param> /// <returns></returns> protected IActionResult Post(IVmOpenApiGeneralDescriptionInVersionBase request) { if (request == null) { ModelState.AddModelError("RequestIsNull", CoreMessages.OpenApi.RequestIsNull); return(new BadRequestObjectResult(ModelState)); } // Validate the items if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } // Get the base model for service request = request.VersionBase(); // Check the item values from db and validate ValidateParameters(request); if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var result = GeneralDescriptionService.AddGeneralDescription(request, Settings.AllowAnonymous, versionNumber); return(Ok(result)); }
private void CheckTranslations(IVmOpenApiGeneralDescriptionInVersionBase source, StatutoryServiceGeneralDescriptionVersioned target) { target.Names.First().Name.Should().Be(source.Names.First().Value); target.Descriptions.First().Description.Should().Be(source.Descriptions.First().Value); target.Languages.FirstOrDefault(lc => lc.Language.Code == LanguageCode.fi.ToString()).Should().NotBeNull(); target.Languages.FirstOrDefault(lc => lc.Language.Code == LanguageCode.sv.ToString()).Should().NotBeNull(); target.ServiceClasses.First().ServiceClass.Uri.Should().Be(source.ServiceClasses.First()); target.OntologyTerms.First().OntologyTerm.Uri.Should().Be(source.OntologyTerms.First()); target.TargetGroups.First().TargetGroup.Uri.Should().Be(source.TargetGroups.First()); target.LifeEvents.First().LifeEvent.Uri.Should().Be(source.LifeEvents.First()); }
/// <summary> /// Updates the defined general description with the data provided as input. /// </summary> /// <param name="id"></param> /// <param name="request"></param> /// <returns></returns> protected IActionResult Put(string id, IVmOpenApiGeneralDescriptionInVersionBase request) { if (request == null) { ModelState.AddModelError("RequestIsNull", CoreMessages.OpenApi.RequestIsNull); return(new BadRequestObjectResult(ModelState)); } if (!string.IsNullOrEmpty(id)) { request.Id = id.ParseToGuid(); // check that general description exists if (!request.Id.HasValue || !GeneralDescriptionService.GeneralDescriptionExists(request.Id.Value)) { return(NotFound(new VmError() { ErrorMessage = $"General description with id '{id}' not found." })); } } else { return(NotFound(new VmError() { ErrorMessage = $"General description with id '{id}' not found." })); } // Validate the items if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } // get the base model for service request = request.VersionBase(); // Check the item values from db and validate ValidateParameters(request, false); if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var result = GeneralDescriptionService.SaveGeneralDescription(request, versionNumber); return(Ok(result)); }