/// <summary>
        ///Post service base.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="attachProposedChannels"></param>
        /// <returns></returns>
        protected IActionResult Post(IVmOpenApiServiceInVersionBase request, bool attachProposedChannels = false)
        {
            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
            if (request.PublishingStatus != PublishingStatus.Published.ToString())
            {
                request.PublishingStatus = PublishingStatus.Draft.ToString();
            }

            ServiceValidator service = new ServiceValidator(request, generalDescriptionService, codeService, fintoService, commonService, channelService, request.AvailableLanguages, UserRole());

            service.Validate(this.ModelState);

            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            var result = serviceService.AddService(request, Settings.AllowAnonymous, versionNumber, attachProposedChannels);

            return(Ok(result));
        }
        /// <summary>
        /// Put service base.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="id"></param>
        /// <param name="sourceId"></param>
        /// <param name="attachProposedChannels"></param>
        /// <returns></returns>
        protected IActionResult Put(IVmOpenApiServiceInVersionBase request, string id = null, string sourceId = null, bool attachProposedChannels = false)
        {
            if (request == null)
            {
                ModelState.AddModelError("RequestIsNull", CoreMessages.OpenApi.RequestIsNull);
                return(new BadRequestObjectResult(ModelState));
            }

            if (id.IsNullOrEmpty() && sourceId.IsNullOrEmpty())
            {
                return(NotFound(new VmError()
                {
                    ErrorMessage = $"Service with id '{id}' not found."
                }));
            }

            // get the base model for service
            request = request.VersionBase();

            // Validate the items
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            IVmOpenApiServiceVersionBase currentVersion = null;

            if (!string.IsNullOrEmpty(id))
            {
                Guid?serviceId = id.ParseToGuid();

                // check that service exists
                if (!serviceId.HasValue)
                {
                    return(NotFound(new VmError()
                    {
                        ErrorMessage = $"Service with id '{id}' not found."
                    }));
                }

                request.Id     = serviceId;
                currentVersion = serviceService.GetServiceByIdSimple(request.Id.Value, false);
            }
            else if (!string.IsNullOrEmpty(sourceId))
            {
                currentVersion = serviceService.GetServiceBySource(sourceId);
            }

            // Check current version and data
            if (currentVersion == null || string.IsNullOrEmpty(currentVersion.PublishingStatus))
            {
                if (request.Id.IsAssigned())
                {
                    return(NotFound(new VmError()
                    {
                        ErrorMessage = $"Service with id '{request.Id.Value}' not found."
                    }));
                }
                else
                {
                    return(NotFound(new VmError()
                    {
                        ErrorMessage = $"Version for service with source id '{sourceId}' not found."
                    }));
                }
            }

            // Has user rights for the service
            var isOwnOrganization = ((VmOpenApiServiceVersionBase)currentVersion).Security == null ? false : ((VmOpenApiServiceVersionBase)currentVersion).Security.IsOwnOrganization;

            if (UserRole() != UserRoleEnum.Eeva && !isOwnOrganization)
            {
                return(NotFound(new VmError()
                {
                    ErrorMessage = $"User has no rights to update or create this entity!"
                }));
            }

            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).
            var newLanguages = request.AvailableLanguages.Where(i => !currentVersion.AvailableLanguages.Contains(i)).ToList();

            // Check the general description data. If current version is attached into general description, service type cannot be updated for service.
            // Except if deleteStatutoryServiceGeneralDescriptionId is true (general description will be removed from the service).
            if (currentVersion.StatutoryServiceGeneralDescriptionId.IsAssigned() && !request.DeleteStatutoryServiceGeneralDescriptionId)
            {
                request.Type = null;
            }

            ServiceValidator service = new ServiceValidator(request, generalDescriptionService, codeService, fintoService, commonService, channelService, newLanguages, UserRole());

            service.Validate(this.ModelState);

            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            return(Ok(serviceService.SaveService(request, Settings.AllowAnonymous, versionNumber, attachProposedChannels, sourceId)));
        }