/*========================================================================================================================== | HELPER: SAVE TO TOPIC \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Adds the form values to a new <see cref="Topic"/>, and saves it to the <see cref="ITopicRepository"/>. /// </summary> private async Task SaveToTopic(ITopicBindingModel bindingModel) { /*------------------------------------------------------------------------------------------------------------------------ | Establish variables \-----------------------------------------------------------------------------------------------------------------------*/ bindingModel.ContentType = bindingModel.GetType().Name.Replace("BindingModel", ""); bindingModel.Key = bindingModel.ContentType + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); /*------------------------------------------------------------------------------------------------------------------------ | Validate Topic Parent \-----------------------------------------------------------------------------------------------------------------------*/ var parentKey = "Administration:Licenses"; var parentTopic = TopicRepository.Load(parentKey); /*------------------------------------------------------------------------------------------------------------------------ | Map binding model to new topic \-----------------------------------------------------------------------------------------------------------------------*/ var topic = await _reverseMappingService.MapAsync(bindingModel); var errorMessage = $"The topic '{parentKey}' could not be found. A root topic to store forms to is required."; /*------------------------------------------------------------------------------------------------------------------------ | Set Topic values \-----------------------------------------------------------------------------------------------------------------------*/ topic.Parent = parentTopic?? throw new Exception(errorMessage); topic.LastModified = DateTime.Now; /*------------------------------------------------------------------------------------------------------------------------ | Save form Topic \-----------------------------------------------------------------------------------------------------------------------*/ TopicRepository.Save(topic); }
/*========================================================================================================================== | HELPER: SAVE TO TOPIC \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Adds the form values to a new <see cref="Topic"/>, and saves it to the <see cref="ITopicRepository"/>. /// </summary> private async Task SaveToTopic(CoreContact bindingModel) { /*------------------------------------------------------------------------------------------------------------------------ | Establish variables \-----------------------------------------------------------------------------------------------------------------------*/ var contentType = bindingModel.GetType().Name.Replace("BindingModel", "", StringComparison.Ordinal); bindingModel = bindingModel with { ContentType = contentType, Key = contentType + "_" + DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) }; /*------------------------------------------------------------------------------------------------------------------------ | Validate Topic Parent \-----------------------------------------------------------------------------------------------------------------------*/ var parentKey = "Administration:Licenses"; var parentTopic = TopicRepository.Load(parentKey); /*------------------------------------------------------------------------------------------------------------------------ | Map binding model to new topic \-----------------------------------------------------------------------------------------------------------------------*/ var topic = await _reverseMappingService.MapAsync(bindingModel).ConfigureAwait(true); var errorMessage = $"The topic '{parentKey}' could not be found. A root topic to store forms to is required."; /*------------------------------------------------------------------------------------------------------------------------ | Set Topic values \-----------------------------------------------------------------------------------------------------------------------*/ topic.Parent = parentTopic?? throw new InvalidOperationException(errorMessage); topic.LastModified = DateTime.Now; /*------------------------------------------------------------------------------------------------------------------------ | Save form Topic \-----------------------------------------------------------------------------------------------------------------------*/ TopicRepository.Save(topic); }