Пример #1
0
        /// <summary>
        /// Configures the phrase
        /// </summary>
        /// <param name="configuration">The phrase configuration</param>
        public void Configure
        (
            RegisteredPhraseConfiguration configuration
        )
        {
            this.PhraseText = configuration.PhraseText;

            if (configuration.Translations != null)
            {
                this.Translations.Clear();

                foreach (var translation in configuration.Translations)
                {
                    this.Translations.Add
                    (
                        new RegisteredPhraseTranslation
                        (
                            this,
                            translation.Key,
                            translation.Value
                        )
                    );
                }
            }

            this.DateModified = DateTime.UtcNow;
            this.Version++;
        }
Пример #2
0
        /// <summary>
        /// Constructs the phrase with the text
        /// </summary>
        /// <param name="configuration">The phrase configuration</param>
        internal RegisteredPhrase
        (
            RegisteredPhraseConfiguration configuration
        )
        {
            this.Id           = Guid.NewGuid();
            this.DateCreated  = DateTime.UtcNow;
            this.Translations = new Collection <RegisteredPhraseTranslation>();

            Configure(configuration);
        }
Пример #3
0
        /// <summary>
        /// Configures a phrase
        /// </summary>
        /// <param name="id">The phrase ID</param>
        /// <param name="configuration">The phrase configuration</param>
        public void ConfigurePhrase
        (
            Guid id,
            RegisteredPhraseConfiguration configuration
        )
        {
            var phrase = _phraseRepository.GetPhrase(id);

            phrase.Configure(configuration);

            _phraseRepository.UpdatePhrase(phrase);
            _unitOfWork.SaveChanges();

            RegisteredPhraseTranslatorFactory.ClearCache();
        }
Пример #4
0
        /// <summary>
        /// Creates a phrase
        /// </summary>
        /// <param name="configuration">The phrase configuration</param>
        /// <returns>The phrase created</returns>
        public RegisteredPhrase CreatePhrase
        (
            RegisteredPhraseConfiguration configuration
        )
        {
            EnsurePhraseAvailable(configuration);

            var phrase = new RegisteredPhrase
                         (
                configuration
                         );

            _phraseRepository.AddPhrase(phrase);
            _unitOfWork.SaveChanges();

            RegisteredPhraseTranslatorFactory.ClearCache();

            return(phrase);
        }
Пример #5
0
        /// <summary>
        /// Ensures a phrase is available to be registered
        /// </summary>
        /// <param name="configuration">The phrase configuration</param>
        private void EnsurePhraseAvailable
        (
            RegisteredPhraseConfiguration configuration
        )
        {
            Validate.IsNotNull(configuration);

            var text = configuration.PhraseText;

            var phrase = _phraseRepository.FindPhrase
                         (
                text
                         );

            if (phrase != null)
            {
                throw new InvalidOperationException
                      (
                          $"The '{text}' has already been registered."
                      );
            }
        }