/// <summary> /// Save organization. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> protected IActionResult Post(IVmOpenApiOrganizationInVersionBase 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 organization request = request.VersionBase(); // Check the item values from db and validate ValidateParameters(request, true); if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var result = organizationService.AddOrganization(request, Settings.AllowAnonymous, versionNumber); return(Ok(result)); }
/// <summary> /// Change the organization. /// </summary> /// <param name="request">The request.</param> /// <param name="id">The identifier.</param> /// <param name="sourceId">The source identifier.</param> /// <returns></returns> protected IActionResult Put(IVmOpenApiOrganizationInVersionBase request, string id = null, string sourceId = null) { // check that one of identifiers is defined if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(sourceId)) { return(NotFound(new VmError() { ErrorMessage = $"Organization with id '{id}' not found." })); } // check that the resource exists that we are about to update - id is used, not source id if (!string.IsNullOrEmpty(id) && !CheckOrganizationExists(id)) { return(NotFound(new VmError() { ErrorMessage = $"Organization with id '{id}' not found." })); } 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 organization request = request.VersionBase(); if (!string.IsNullOrEmpty(id)) { request.Id = id.ParseToGuid(); } if (!string.IsNullOrEmpty(sourceId)) { request.SourceId = sourceId; } // Validate item values from db and validate var validationResult = ValidateRequest(request); return(validationResult ?? Ok(organizationService.SaveOrganization(request, Settings.AllowAnonymous, versionNumber))); }