Exemple #1
0
        public ActionResult CreateTextResource([FromBody] TextResourceContract textResource)
        {
            ResultContract result;

            try
            {
                result = m_textResourceManager.CreateTextResource(textResource);
            }
            catch (ArgumentException exception)
            {
                return(BadRequest(exception.Message));
            }

            return(Ok(result));
        }
        public string CreateTextResource(string text, int versionNumber)
        {
            var textResource = new TextResourceContract {
                PageText = text, VersionNumber = versionNumber
            };

            try
            {
                var result = m_client.Post <ResultContract>("text", textResource);
                return(result.Id);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
        public ResultContract CreateTextResource(TextResourceContract textResource)
        {
            var validationResult = m_textValidator.Validate(textResource.PageText);

            if (!validationResult.IsValid)
            {
                throw new ArgumentException(validationResult.ErrorMessage);
            }

            var client   = m_communicationProvider.GetElasticClient();
            var response = client.Index(textResource, idx => idx.Index(PageIndex).Type(PageType));

            if (!response.IsValid)
            {
                throw new FulltextDatabaseException(response.DebugInformation);
            }

            return(new ResultContract {
                Id = response.Id
            });
        }