/// <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++; }
/// <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); }
/// <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(); }
/// <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); }
/// <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." ); } }