Перейти к содержанию

Расширение на сохранение карточки с созданием обсуждения

Расширение на сохранение карточки с созданием обсуждения

Note

Создание обсуждений важно выполнять на существующей карточке, но не обязательно это делать именно в серверных расширениях, как показано в примере.

Реализация расширения

public sealed class ForumCardStoreExtension : CardStoreExtension { #region Private Fields

private readonly IForumProvider forumProvider;

private readonly IDbScope dbScope;

private readonly ICardRepository cardRepository;

#endregion

#region Constructors

public SupportCardStoreExtension( ICardRepository cardRepository, IForumProvider forumProvider, IDbScope dbScope) { this.cardRepository = cardRepository; this.forumProvider = forumProvider; this.dbScope = dbScope; }

#endregion

#region Base Override

public override async Task AfterRequest(ICardStoreExtensionContext context) { if (!context.ValidationResult.IsSuccessful()) { return; }

var card = context.Request.Card;

var responseAddTopic = await this.forumProvider.AddTopicAsync( card.ID, new TopicModel() { Title = "Название обсуждения", AuthorID = authorID, TypeID = ForumHelper.TopicDefaultType }, context.CancellationToken);

if (!responseAddTopic.ValidationResult.IsSuccessful()) { context.ValidationResult.Add(responseAddTopic.ValidationResult); return; }

var topic = new TopicModel(responseAddTopic.Info[ForumProvider.TopicModelKey] as Dictionary<string, object>);

// Для примера, добавим в участники текущего сотрудника var participants = new List<Guid>() { context.Session.User.ID };

// Добавляет участников в обсуждение, как конкретных сотрудников response = await this.forumProvider.AddParticipantsAsync( topic.ID, participants, false, ParticipantTypes.Participant, false, false, context.CancellationToken);

if (!response.ValidationResult.IsSuccessful()) { context.ValidationResult.Add(response.ValidationResult); return; } }

#endregion }

Регистрация расширения

[Registrator] public sealed class Registrator : RegistratorBase { public override void RegisterExtensions(IExtensionContainer extensionContainer) { extensionContainer .RegisterExtension<ICardStoreExtension, ForumCardStoreExtension>(x => x .WithOrder(ExtensionStage.AfterPlatform) .WithUnity(this.UnityContainer) .WhenCardTypes(CardHelper.TypeID)); } }

Back to top