namespace Brizco.Repository.MartenHandlers.NewsFeeds; public class CreateNewsFeedCommandHandler (IMartenRepositoryWrapper martenRepositoryWrapper , ICurrentUserService currentUserService) : IRequestHandler { public async Task Handle(CreateNewsFeedCommand request, CancellationToken cancellationToken) { if (currentUserService.ComplexId == null) throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null"); if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId)) throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong"); var newsFeed = new NewsFeed { ComplexId = complexId, Content = request.Content, Title = request.Title, IsPin = request.IsPin }; await martenRepositoryWrapper.SetRepository().AddOrUpdateEntityAsync(newsFeed, cancellationToken); return newsFeed.Id; } }